Results 1 to 11 of 11

Thread: [2008] Glassy aero form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    23

    [2008] Glassy aero form

    Is there any way I can use the aero glassy effect in my window forms in vb.net - I've seen a couple of exmaples in vc and even vb6, but not .net (the vb6>>.net conversion goes a bit wrong so I still cant use it).

    Essentially I'm trying to create an aesthetically pleasing irregular but vista-consistent ui for a small lightweight app, the ui like the one used in speech recognition:



    Any suggestions?

    Many thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: [2008] Glassy aero form

    you can use an image for your form background + change the shape of the form using its region property. i've got some code that creates a rounded rectangle graphicspath that you can use to create the new region. i'll post it as soon as i find it

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: [2008] Glassy aero form

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         Me.Region = New Region(roundedRectangle(0, 0, 500, 200, 50))
    6.  
    7.     End Sub
    8.  
    9.     Public Function roundedRectangle(ByVal X As Integer, ByVal Y As Integer, _
    10.         ByVal Width As Integer, ByVal Height As Integer, ByVal diameter As Integer) As System.Drawing.Drawing2D.GraphicsPath
    11.  
    12.         ''the 'diameter' parameter changes the size of the rounded region
    13.  
    14.         Dim graphics_path As New System.Drawing.Drawing2D.GraphicsPath
    15.  
    16.         Dim BaseRect As New RectangleF(X, Y, Width, Height)
    17.         Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(diameter, diameter))
    18.  
    19.         'top left Arc
    20.         graphics_path.AddArc(ArcRect, 180, 90)
    21.         graphics_path.AddLine(X + CInt(diameter / 2), _
    22.         Y, X + Width - CInt(diameter / 2), Y)
    23.  
    24.         ' top right arc
    25.         ArcRect.X = BaseRect.Right - diameter
    26.         graphics_path.AddArc(ArcRect, 270, 90)
    27.         graphics_path.AddLine(X + Width, _
    28.         Y + CInt(diameter / 2), X + Width, _
    29.                          Y + Height - CInt(diameter / 2))
    30.  
    31.         ' bottom right arc
    32.         ArcRect.Y = BaseRect.Bottom - diameter
    33.         graphics_path.AddArc(ArcRect, 0, 90)
    34.         graphics_path.AddLine(X + CInt(diameter / 2), _
    35.         Y + Height, X + Width - CInt(diameter / 2), _
    36.                          Y + Height)
    37.  
    38.         ' bottom left arc
    39.         ArcRect.X = BaseRect.Left
    40.         graphics_path.AddArc(ArcRect, 90, 90)
    41.         graphics_path.AddLine(X, Y + CInt(diameter / 2), _
    42.         X, Y + Height - CInt(diameter / 2))
    43.  
    44.         Return graphics_path
    45.  
    46.     End Function
    47.  
    48. End Class

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: [2008] Glassy aero form

    the original form (you can set the region of controls too) has to be larger than the new region or it won't display properly

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    23

    Re: [2008] Glassy aero form

    Cheers paul. Its a nice simple workaround for the moment, though I'll still be open to suggestions, since finding a faux transparent bg to suit all colours isnt easy to get right.

    Also, I'm hoping to be able to use a gui such as this in the future:



    Many thanks
    Last edited by Tuna; Jan 16th, 2008 at 01:34 PM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Glassy aero form

    Surely if you want to support Aero Glass then you should be using WPF, not Windows Forms.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2008] Glassy aero form

    AeroGlass is a Vista theme. You dont have to do anything to get the Aero theme applied to your form when its run on Vista. Now the rounded glassy button is a different story. If its just advanced graphics you want then using the GDI+ classes is enough but to mimic the aero theming on custom controls will require the use of the WPF like John posted.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Glassy aero form

    Check this out, it might help you (there's a VB code too, scroll a bit down):
    http://www.aeroxp.org/board/lofivers...php?t1641.html

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    23

    Re: [2008] Glassy aero form

    Cheers though it says 'InitializeComponent' is not declared:

    Code:
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    Namespace GlassTest
       Public Class Form1
           Inherits Form
    
           ' Import functions from dwmapi.dll - get this info from the sdk dwmapi.h
           <DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
           Public Shared Sub DwmExtendFrameIntoClientArea(ByVal hWnd As System.IntPtr, ByRef pMargins As Margins)
           End Sub
    
           <DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
           Public Shared Sub DwmIsCompositionEnabled(ByRef IsIt As Boolean)
           End Sub
    
           ' Create the brush that'll work around the Alpha transparency issue
           Private DWMFrame As SolidBrush = New SolidBrush(Color.Black)
    
           ' Define the Margins struct - get this from dwmapi.h
           Public Structure Margins
               Public Left As Integer
               Public Right As Integer
               Public Top As Integer
               Public Bottom As Integer
           End Structure
    
           ' Create an instance of the Margins struct for use in our form
           Private inset As Margins = New Margins
    
           Public Sub New()
               InitializeComponent()
               AddHandler Me.Paint, AddressOf Me.Form1_Paint
    
               ' Set the Margins to their default values
               inset.Top = 40
               inset.Left = 0
               inset.Right = 0
               inset.Bottom = 0
    
               ' Check if DWM is enabled. This is a pretty stupid way to check, since it requires dwmapi.dll to be present anyway...
               Dim isit As Boolean = False
               DwmIsCompositionEnabled(isit)
    
               If isit Then
                   ' If DWM is enabled, call the function that gives us glass, passing a reference to our inset Margins
                   DwmExtendFrameIntoClientArea(Me.Handle, inset)
               Else
                   ' If DWM isn't enabled, shout it out
                   MessageBox.Show("DWM isn't enabled")
               End If
           End Sub
    
           ' We need to override the Paint event as well as call the glass function. This is because of WindowsForms and Alpha-blending...
           Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
               e.Graphics.FillRectangle(DWMFrame, 0, 0, Width, inset.Top)
               e.Graphics.FillRectangle(DWMFrame, 0, 0, inset.Left, Height)
               ' Note the numbers ( -14, -34) are just trial-and-error values, used to fix the glass... try omitting them, you'll get the idea.            
               e.Graphics.FillRectangle(DWMFrame, Width - inset.Right - 14, 0, inset.Right, Height)
               e.Graphics.FillRectangle(DWMFrame, 0, Height - inset.Bottom - 34, Width, inset.Bottom)
           End Sub
       End Class
    End Namespace
    Any suggestions?

  10. #10
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Glassy aero form

    It worked for me, although I think I might have left out the "Namespace GlassTest" and "End Namespace" bits... Not sure though

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2008] Glassy aero form

    You should not be using the New constructor or the Paint event to do aero as its better to use the OnPaint overrides instead if you are not going to use WPF.

    Just try writting on glass with the non-WPF methods
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width