OK. You won't do this through the Framework, you will have to use some
uxtheme functions. You will also need to monitor for the theme changes.
The following code will do what you want. The Color I chose was Color1 of
the two color gradient of the TasksPanel in Explorer:
**** Code starts **********************************************
#Region " XP Theme API "
'The uxtheme.dll function IsAppThemed() returns True
'if only the TitleBar has Visual Styles applied. A
'better way to check for Visual Styles is to check
'whether Comctl32.dll version 6 is in use.
Private Structure DLLVERSIONINFO
Dim cbSize As Integer
Dim dwMajorVersion As Integer
Dim dwMinorVersion As Integer
Dim dwBuildNumber As Integer
Dim dwPlatformID As Integer
End Structure
<DllImport("Comctl32.dll", _
entrypoint:="DllGetVersion", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Overloads Shared Function IsAppThemed( _
ByRef pdvi As DLLVERSIONINFO) As Integer
End Function
<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl, _
CharSet:=CharSet.Unicode)> _
Private Shared Function OpenThemeData( _
ByVal hwnd As IntPtr, _
ByVal pszClassList As String) As IntPtr
End Function
<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function CloseThemeData( _
ByVal hTheme As IntPtr) As Integer
End Function
<DllImport("UxTheme.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function GetThemeColor( _
ByVal hTheme As IntPtr, _
ByVal iPartID As Integer, _
ByVal iStateId As Integer, _
ByVal iPropId As Integer, _
ByRef pColor As rgbColor) As Integer
End Function
Private Const EBP_HEADERBACKGROUND As Integer = 1
Private Const TMT_GRADIENTCOLOR1 As Integer = 3810
Private Const TMT_GRADIENTCOLOR2 As Integer = 3811
Private Const TMT_GRADIENTCOLOR3 As Integer = 3812
Private Const TMT_GRADIENTCOLOR4 As Integer = 3813
Private Const TMT_GRADIENTCOLOR5 As Integer = 3814
Private S_OK As Integer = 0
Private Const WM_THEMECHANGED As Integer = &H31A
Private Structure rgbColor
Dim r As Byte
Dim g As Byte
Dim b As Byte
End Structure
#End Region
Private Function SetFormColor() As Boolean
Dim ReturnValue As Boolean = False
'----Check we are using Visual Styles
Dim dvi As New DLLVERSIONINFO
dvi.cbSize = Marshal.SizeOf(dvi)
IsAppThemed(dvi)
If dvi.dwMajorVersion < 6 Then Return False
'----------------------------------
Dim hTheme As IntPtr = OpenThemeData(Me.Handle, _
"EXPLORERBAR")
If Not hTheme.Equals(IntPtr.Zero) Then
Dim c As New rgbColor
If GetThemeColor(hTheme, EBP_HEADERBACKGROUND, 0, _
TMT_GRADIENTCOLOR1, _
c) = S_OK Then
Me.BackColor = Color.FromArgb(255, c.r, c.g, c.b)
ReturnValue = True
End If
End If
CloseThemeData(hTheme)
Return ReturnValue
End Function
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
SetFormColor()
End Sub
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_THEMECHANGED Then SetFormColor()
End Sub
**** Code ends ***********************************************
HTH
Mick