Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

UXTheme.dll, VB, Tab and Groupbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Corbett - 12 Sep 2003 16:45 GMT
I am trying to implement visual themes for a tab page in VB.NET, I have
derived a new tab page class to use the UXTheme.dll methods to draw visual
themes, but the problem I'm having is getting Groupboxes and checkboxes to
display correctly on the Tab Page, I have searched for ages on the web and
am unable to find the solution. If anyone can point me to an example of this
in VB.net (I have one from code project in c#/c++ - but can't get it to
work) - or if anyone knows how to  do this - help would be appreciated.

Regards
Brian Corbett
Kevin Westhead - 12 Sep 2003 22:59 GMT
> I am trying to implement visual themes for a tab page in VB.NET, I have
> derived a new tab page class to use the UXTheme.dll methods to draw visual
[quoted text clipped - 3 lines]
> in VB.net (I have one from code project in c#/c++ - but can't get it to
> work) - or if anyone knows how to  do this - help would be appreciated.

I believe you need to derive new GroupBox and CheckBox controls and draw
their backgrounds using uxtheme in the same way that you're doing for the
TabControl.

Signature

Kevin Westhead

Brian - 13 Sep 2003 15:37 GMT
Kevin, thanks for your reply - unfortunately thats exactly what I am
struggling with - I have derived a tabpage and groupbox and can get them
to draw lovely - but as soon as I put the groupbox on the tabpage it
goes back to how it was - with out drawing the correct gradient onto the
groupbox. Really struggling to get this to work.

Thanks
Brian Corbett
Kevin Westhead - 13 Sep 2003 15:49 GMT
> Kevin, thanks for your reply - unfortunately thats exactly what I am
> struggling with - I have derived a tabpage and groupbox and can get them
> to draw lovely - but as soon as I put the groupbox on the tabpage it
> goes back to how it was - with out drawing the correct gradient onto the
> groupbox. Really struggling to get this to work.

I haven't actually implemented anything like this myself, but my
understanding is that, when the GroupBox is contained within a themed
TabPage, you need to give it a transparent background colour and paint it's
background using DrawThemeParentBackground instead of DrawThemeBackground.
It's difficult to offer anymore help without knowing a bit more about what
you're doing; can you post some code?

Signature

Kevin Westhead

Brian - 13 Sep 2003 21:52 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.