Results 1 to 6 of 6

Thread: [.NET 1.0+] Explorer Themed Controls (Windows Aero Visuals)

Threaded View

  1. #1

    Thread Starter
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    [.NET 1.0+] Explorer Themed Controls (Windows Aero Visuals)

    Fairly simple, using the SetWindowTheme API call you can change the appearance of a couple controls so that they look a bit nicer:

    Before:
    Name:  SetWindowTheme_Before.png
Views: 3186
Size:  32.2 KB

    After:
    Name:  SetWindowTheme_After.png
Views: 3061
Size:  28.7 KB

    Code:
    Code:
    Public Class UnsafeNativeMethods
    
        '//the character set needs to be Unicode
        <DllImport("uxtheme.dll", CharSet:=CharSet.Unicode)> _
        Friend Shared Function SetWindowTheme(ByVal hWnd As IntPtr, _
                                              ByVal pszSubAppName As String, _
                                              ByVal pszSubIdList As String) As Integer
        End Function
    
    End Class
    Example implementation:

    Code:
    ''' <summary>
    ''' Applies the explorer theme to the specified control.
    ''' </summary>
    ''' <param name="control">Indicates the control to apply the theme to.</param>
    Public Function ApplyTheme(ByVal control As Control) As Integer
        Return Me.ApplyTheme(control, "Explorer")
    End Function
    
    Private Function ApplyTheme(ByVal control As Control, ByVal theme As String) As Integer
        Try
            If control IsNot Nothing Then
                If control.IsHandleCreated Then
                    Return UnsafeNativeMethods.SetWindowTheme(control.Handle, theme, Nothing)
                End If
            End If
        Catch ex As DllNotFoundException
            Return -1
        End Try
        Return -1
    End Function
    
    ''' <summary>
    ''' Clears the applied theme from the specified control.
    ''' </summary>
    ''' <param name="control">Indicates the control to clear the theme from.</param>
    Public Function ClearTheme(ByVal control As Control) As Integer
        Return Me.ApplyTheme(control, String.Empty)
    End Function
    Last edited by ForumAccount; Jul 8th, 2011 at 12:26 PM. Reason: Applied different styling

Tags for this Thread

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