none
vista aero glass rendering help RRS feed

  • Question

  • Hello everyone,  I have another question.  I have recently found out how to extend the vista aero glass.  Im using winforms not wpf.  I need to learn how to render text and button objects correctly onto the form.  Below are two pictures.  One of an example of a clear form produced by another company and it works great and the seccond one of my form but with some problems. 

    aero,look

    problem .

    As you can see in the picture above me the button label and text box aren't rendered as well as they could be where as the radio button and picture box render just perfect.  now the way the code for the main window is set up anything outside the main space (all that is outside of the white box) is setup to take black and make it into glass.  so the text inside of the textbox is actually glass.  I know that there are api's to render these controls just right so that they appear like they would inside of the main space.  but what i need to know is how to do just that.  what are the api calles and the code nessary to programaticly change the controls to look like they are in the main area but are techenicly out in the glass.   as it is all of these controlls are set to a backcolor of black and it works for the picturebox but nothing else.  the label looks fine there unless the window goes above something with a white background.  i would like to have text rendered in the same way that the text for the window name is.  so how would i do this?



    below is the code that i used to get the aero glass.  just a little something to play arround wit.
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    
    Public Class Foreform
    
        Private mExtendedFrameMargins As MARGINS
    
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, 
    
            mExtendedFrameMargins = New MARGINS
            mExtendedFrameMargins.cyTopHeight = 50
            mExtendedFrameMargins.cyBottomHeight = 20
            mExtendedFrameMargins.cxLeftWidth = 150
    
            If IsGlassEnabled() Then
                DwmExtendFrameIntoClientArea(Me.Handle, mExtendedFrameMargins)
            End If
            'two line shapes have been added to create a definging area between the title bar and the other aero glass
            LineShape1.X2 = Screen.PrimaryScreen.WorkingArea.Width
            LineShape2.X2 = Screen.PrimaryScreen.WorkingArea.Width
            'the backform refers to the form i have behind this one to produce a color behind the original form
            Backform.Show()
    
    
        End Sub
    
     
    
        Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            If IsGlassEnabled() Then
                'You should paint the extended frame black for proper composition.
                e.Graphics.FillRectangle(Brushes.Black, 0, 0, Me.ClientRectangle.Width, mExtendedFrameMargins.cyTopHeight)
                e.Graphics.FillRectangle(Brushes.Black, 0, Me.ClientSize.Height - 20, Me.ClientRectangle.Width, mExtendedFrameMargins.cyBottomHeight)
                e.Graphics.FillRectangle(Brushes.Black, 0, 0, mExtendedFrameMargins.cxLeftWidth, Me.ClientSize.Height)
    
            End If
            Backform.Width = Me.Width
            Backform.Location = Me.Location
        End Sub
    
        Private Function IsGlassEnabled() As Boolean
            If Environment.OSVersion.Version.Major < 6 Then
                Return False
    
            End If
    
            Dim isGlassSupported As Boolean = False
            DwmIsCompositionEnabled(isGlassSupported)
            Return isGlassSupported
        End Function
    
        <DllImport("dwmapi.dll")> _
        Private Shared Function DwmIsCompositionEnabled(<MarshalAs(UnmanagedType.Bool)> ByRef pfEnabled As Boolean) As Integer
        End Function
    
        <DllImport("dwmapi.dll")> _
        Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer
        End Function
    
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure MARGINS
            Public cxLeftWidth As Integer
            Public cxRightWidth As Integer
            Public cyTopHeight As Integer
            Public cyBottomHeight As Integer
        End Structure
    
    
    
        Private Sub Form1_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
            'keeps the backform behind the mainform
            Backform.Location = Me.Location
        End Sub
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    
            Me.Height = Screen.PrimaryScreen.WorkingArea.Height + 4
            Me.Left = Screen.PrimaryScreen.WorkingArea.Left
            Me.Top = Screen.PrimaryScreen.WorkingArea.Top - 2
            Me.Width = Screen.PrimaryScreen.WorkingArea.Width
            Me.UpdateZOrder()
            Backform.Opacity = 80%
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
            'closes the backback form if the main form closes
            My.Settings.Save()
            Backform.Close()
        End Sub
    
    
        Private Sub Foreform_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
            'some code that is suppose to bring the backform into second in the z axis (dosen't really work)
            Backform.BringToFront()
            Me.BringToFront()
        End Sub
    
    
    End Class
    
    

    • Edited by ILPX Friday, June 26, 2009 3:28 AM add code
    Thursday, June 25, 2009 7:48 PM

Answers

  • ILPX..
    i might have solved your button problem, for starters..
    to get a properly viewed button, create a image with text, and add it as the button1 image.
    you probably have to do other images for mouseover, mouse leave events, but at least the button shows properly..

    i'll look into the other stuff.
    trujade.
    help out microsoft for helping you.. test run 7
    Friday, June 26, 2009 4:14 AM

All replies

  • if you notice, your posted code, is scrambled everywhere.
    this is due to editing a post, a minor msdn error that needs to be fixed.

    i am only replying with such, because it is your question post, that includes code.
    so, if you want anyone to be able to use the code and give feedback to your question, you have to edit and insert the code snippet again, code snippet being the last to be inserted in your post.. this seems to work and keeps the code viewable and useable.

    hope this helps answer your question sooner. ;o)
    trujade.
    help out microsoft for helping you.. test run 7
    Thursday, June 25, 2009 10:21 PM
  • thanks trujade...but from the looks of it no body wants to take a shot at this one...im going to search online for possible answers  thanks anyway
    Thursday, June 25, 2009 11:18 PM
  • ILPX

    Yes there is a few API that help the look, but it is not perfect.

    however, there is an easy way to get a nice look:

    just paint on your form a white square behind your button, textbox, and all dark control that are not rendered ok.

    You will have a perfect effect.

    Friday, June 26, 2009 2:41 AM
  • but wont this make a white square behind it?
    Friday, June 26, 2009 2:42 AM
  • am i missing something, or did the forum view change from the last time i was online, replying to this question.. kinda nice.

    about your question..
    ILXP, post the code back on here, so we have something to play around with, maybe come up with a solution..
    help out microsoft for helping you.. test run 7
    Friday, June 26, 2009 3:05 AM
  • alright ill put the code back on.
    Friday, June 26, 2009 3:21 AM
  • XLPX

    I red back your question and I gave you a wrong answer i think.

    What you want is to have the textbox that have a look like the label have.

    use:  Textbox1.Backcolor=Color.Black  and Textbox1.Forecolor=Color.White

    and the textbox will appear  exactly as the label appear, with a transparent background

    The button never takes a good trensparency, but all the other controls does.

    Just remember, anything black will be transparent on the glass area
    Friday, June 26, 2009 3:30 AM
  • ILPX people lol...

    okay im looking for those api's not a quick and simple way to get this done but rather the full blown api....i need the api calls and the code behind it.  links would be great a link to somewhere i can find the api call and code or even a downloadable example. 
    Friday, June 26, 2009 4:01 AM
  • ILPX..
    i might have solved your button problem, for starters..
    to get a properly viewed button, create a image with text, and add it as the button1 image.
    you probably have to do other images for mouseover, mouse leave events, but at least the button shows properly..

    i'll look into the other stuff.
    trujade.
    help out microsoft for helping you.. test run 7
    Friday, June 26, 2009 4:14 AM
  • You might try custom controls like the button so you can override the Onpaint event and paint the controls yourself .


    Coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Friday, June 26, 2009 4:29 AM
  • scratch that mouse over, mouse leave images deals..

    create a transparent image and only add text.. ;o)
    help out microsoft for helping you.. test run 7
    Friday, June 26, 2009 4:30 AM