Kevin here is the Code for the TabPage. Note: anything that calls
theme.xxxxxxx is the api call itself.
Imports System.Drawing
Imports System.Windows.Forms
Public Class XPTabPage : Inherits System.Windows.Forms.TabPage
Public Sub New()
End Sub
Public Function UseTheme() As Boolean
Return Theme.IsAppThemed() 'This checks to see which version of
the commoncontrols is running
End Function
Protected Overrides Sub OnPaintBackground(ByVal pevent As
System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = pevent.Graphics
If UseTheme() Then
Dim ox As Integer = CInt(g.VisibleClipBounds.X)
Dim oy As Integer = CInt(g.VisibleClipBounds.Y)
Dim dx As Integer = CInt(g.VisibleClipBounds.Width)
Dim dy As Integer = CInt(g.VisibleClipBounds.Height)
If ((ox <> 0) Or (oy <> 0) Or (dx <> Me.Width) Or (dy <>
Me.Height)) Then
PaintChildrenBackground(g, Me, New Rectangle(ox, oy, dx,
dy), 0, 0)
Else
ThemedPaintBackground(g, 0, 0, Me.Width, Me.Height, 0,
0)
End If
Else
MyBase.OnPaintBackground(pevent)
End If
End Sub
Private Function PaintChildrenBackground(ByVal g As Graphics, ByVal
control As Control, ByVal Parentrect As Rectangle, ByVal ofx As Integer,
ByVal ofy As Integer) As Boolean
'Parent Rect is the TabPage
'ChildFind is the Rectangle of each control
'See if ParentRect contains the Child - and drawit with xp
themes
Dim child As Control
For Each child In control.Controls
'Declare the Size of the Rectangle to the same as the
control
Dim FindRect As New Rectangle(child.Location, child.Size)
'Now see if the ChildControl actually encopases the Passed
in Rectangle
If FindRect.Contains(Parentrect) Then
Dim ChildRect As Rectangle = Parentrect
ChildRect.Offset(-child.Left, -child.Top)
If Me.PaintChildrenBackground(g, child, ChildRect, ofx +
child.Left, ofy + child.Top) Then
Return True
End If
'Dim hdc As IntPtr = g.GetHdc()
'Theme.DrawThemeParentBackground(Me.Handle, hdc,
ChildRect)
'DrawBackground("TAB", Theme.TABP_BODY, 1, hdc, 10, 10,
child.Width, child.Height, 10, 10, Me.Width, Me.Height)
'g.ReleaseHdc(hdc)
Me.ThemedPaintBackground(g, child.Left, child.Top,
child.Width, child.Height, ofx, ofy)
Return True
End If
Return False
Next
End Function
Private Function ThemedPaintBackground(ByVal g As Graphics, ByVal ox
As Integer, ByVal oy As Integer, ByVal dx As Integer, ByVal dy As
Integer, ByVal ofx As Integer, ByVal ofy As Integer)
Dim hdc As IntPtr = g.GetHdc()
DrawBackground("TAB", Theme.TABP_BODY, Nothing, hdc, -ofx, -ofy,
Me.Width, Me.Height, ox, oy, dx, dy)
g.ReleaseHdc(hdc)
End Function
Private Function DrawBackground(ByVal Classname As String, _
ByVal PartID As Integer, _
ByVal State As Integer, _
ByVal hdc As IntPtr, _
ByVal ox As Integer, _
ByVal oy As Integer, _
ByVal dx As Integer, _
ByVal dy As Integer, _
ByVal clipox As Integer, _
ByVal clipoy As Integer, _
ByVal clipdx As Integer, _
ByVal clipdy As Integer) As Boolean
Dim ok As Boolean
If UseTheme() Then
Dim htheme As Integer = Theme.OpenThemeData(Nothing,
Classname)
If htheme > 0 Then
Dim rect As New Rectangle(ox, oy, dx, dy)
Dim clip As Rectangle
clip = rect
Try
ok = (0 = (Theme.DrawThemeBackground(htheme, hdc,
PartID, State, rect, clip)))
Catch ex As Exception
End Try
End If
Theme.CloseThemeData(htheme)
End If
End Function
End Class
' ******************* END OF CODE
Kevin, This is the code - the thing is that there is probably a bit of
rubbish in the part where it renders the children controls - but can't
figure out what
Regards
Brian Corbett