Click here to Skip to main content
Email Password   helpLost your password?

Sample Image - TransparentMenu-XPSystemTitleButtons.gif

Introduction

This article will go over some of the least documented (in VB.NET) principles, Transparent Menus and System Title Buttons. This article will discuss how to wrap UxTheme.dll and window events to make a window caption button, and how to hook system menus to make them appear transparent. Please keep in mind that this code is meant for Windows XP, as that is the operating system that I am using, their is no guarantee that this code will work on other Windows operating systems.

Background

Transparent Menu Background: C++ Transparent Menu article was one of the first places on the web that came up when I Googled 'transparent menus' about a year ago. I tried for months to try and convert it to VB.NET but alas with no success. That is until I ran across Flat Visual Studio Style Menus article which shined new hope on the subject, I will explain why later in this article.

Window Titlebar Button Background: This has also been a hard topic to find documentation on, but alas The Code Project had the answer again with MinTrayButton article. This article was written in C# and so was fairly easy to convert to VB.NET. However a drawback was that it did not support XP theming. So I had to modify the code so that it used the Uxtheme.dll to do all the drawing of the caption buttons.

Transparent menu code

As I said this code is based on the article Flat Visual Studio Style Menus. In the code for the article, it had a hook which hooked all system menus of a form and made them appear flat by hooking the menu window and painting a new border on the menu window. Well I took just the hook portion of the flat menu code and added code where it hooked the WM_NCPAINT event.

Select case m.msg
...
Case WM_NCPAINT
  Dim dwstyle As Integer = GetWindowLong(hwnd, GWL_EXSTYLE)
  SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED Or dwstyle)
  SetWindowPos(hwnd, -1, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOACTIVATE _
                         Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE)
  SetLayeredWindowAttributes(hwnd.ToInt32, 0, 150, LWA_ALPHA)
  DrawBorder(hwnd, IntPtr.Zero)
...
End Select

With this code it gets the window handle of the menu popup from the wparameter of the WndProc function. I could then use SetWindowLong and SetLayeredWindowAttributes to set the menu window to appear transparent. This did work and I used the 'DrawBorder' function from the original article code to draw a flat border around the code. I did have to modify the function so that the border drew half-ways properly. A drawback of the current DrawBorder function is that when the mouse goes over a menu item the left border of the menu item will disappear.

Using Transparent menu code

To use the code in your project just copy the component to your project and declare a variable for the TransMenuLib component. Then, in your 'Sub Main' routine include the hooking and unhooking functions. Like:

'you hook your program at the beginning

TransMenuLib.Hook(Process.GetCurrentProcess)
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New Form1)
'and unhook your program at the end

TransMenuLib.Unhook()

WinTrayButton code

To understand the basics of the code I would suggest that you look at the article that this code is based on: MinTrayButton. I will however explain the parts that I have added.

As most Windows programmers know, Windows XP is using the theming engine of UxTheme.dll to draw everything with a UI in the operating system. This also includes caption buttons, which have a total of four states that are painted by UxTheme. The states of Hot, Normal, Pressed, and Disabled are used to show the user if the button is easily accessible or not. I have changed the drawing of the original C# code so that all these states are used. However UxTheme did not have a Windows caption button that did not already have an icon on it, so I decided to use the button that had the smallest icon, the minimize button. This way I could then put an icon over the minimize icon in the minimize button. In the UxTheme.dll the MinButton's part number is 15 and its states are numbers 1-4. However this leads to another solution to a common problem 'What if I want to have a help button in the titlebar when the default buttons (min/max/close) will cover up the form.helpbutton property?'. I have took this into consideration and I have added code so that either the minimize button or the help button can be drawn from UxTheme. The part number in UxTheme for the help button is 23 and its states are the same as those of any of the caption buttons (states 1-4).

Private Sub DrawButton(ByVal g As Graphics, ByVal state As state)
    Select Case parent.FormBorderStyle
        Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
            'small caption button

            If bhelpbutton = True Then
                Select Case state
                    Case state.Normal
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 23, 1, New RECT(New Rectangle(pos.X, _
                          pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Hot
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Pushed
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Disabled
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 23, 4, New RECT(New Rectangle(pos.X, _
                          pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                End Select
            ElseIf bimageonly = False Then
                Select Case state
                    Case state.Normal
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Hot
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Pushed
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                    Case state.Disabled
                        drawThemeBackground(openThemeData(Me.Handle, "Window"), _
                          g.GetHdc, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, _
                          btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
                End Select
            End If
            g = Graphics.FromHdc(New IntPtr(GetWindowDC(parent.Handle.ToInt32)))
            'm.HWnd));


            If bhelpbutton = False Then
                If Not bimagelist Is Nothing Then
                    If bimagelist.Images.Count = 1 Then
                        If state <> state.Disabled Then
                            g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
                        Else
                            ControlPaint.DrawImageDisabled(g, _
                              bimagelist.Images(0), pos.X, pos.Y, _
                              Color.Transparent)
                        End If
                    ElseIf bimagelist.Images.Count = 4 Then
                        Select Case state
                            Case state.Disabled
                                g.DrawImage(bimagelist.Images(3), pos.X, pos.Y)
                            Case state.Hot
                                g.DrawImage(bimagelist.Images(1), pos.X, pos.Y)
                            Case state.Normal
                                g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
                            Case state.Pushed
                                g.DrawImage(bimagelist.Images(2), pos.X, pos.Y)
                        End Select
                    ElseIf bimagelist.Images.Count > 0 Then
                        g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
                    End If
                End If
            End If
            g.Dispose()
 ...
     End Select
End Sub 'DrawButton

Now the other area where I changed the original code a lot is the WndProc subroutine. I have had to change the code to include WinTrayButton clicks, and state changes. This is also the area where I added code to draw the WinTrayButton only when it was necessary.

<System.Security.Permissions.PermissionSet(_
System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As Message)
......
    ' Drawing the Button and getting the Real Size of the Window

    If m.Msg = WM_ACTIVATE OrElse m.Msg = WM_SIZE OrElse m.Msg = _
               WM_SYNCPAINT OrElse m.Msg = WM_NCCREATE OrElse _
               m.Msg = WM_NCPAINT OrElse m.Msg = WM_NCACTIVATE _
               OrElse m.Msg = WM_NCHITTEST OrElse m.Msg = WM_PAINT Then
        If m.Msg = WM_SIZE Then
            wnd_size = New Size(New Point(m.LParam.ToInt32))
        End If
        Dim pnt As New Point(m.LParam.ToInt32)
        If drawn = False Then
            RaiseEvent MinTrayBtnStateChanged(Me, sstate)
        End If
        If parent.Enabled = False Or bEnabled = False Then
            SetState(state.Disabled)
        Else
            If MouseinBtn(pnt) = False Then
                If Not parent.ActiveForm Is parent Then
                    Checkstate(state.Disabled)
                Else
                    Checkstate(state.Normal)
                End If
            Else
                Checkstate(state.Hot)
            End If
        End If
    End If

    MyBase.WndProc(m)

End Sub 'WndProc

The Checkstate function that you see used in this WndProc function checks to make sure that the caption button state is not already the state used in the parameter. The Checkstate function does this by checking to make sure the state of the button is not already the newstate.

 Public Function Checkstate(ByVal newstate As state)
    'if the state is new then change state to the new state and return true

    If sstate <> newstate Then
        sstate = newstate
        RaiseEvent MinTrayBtnStateChanged(Me, sstate)
    End If
End Function

The last part that I will discuss about the WinTrayButton is its help function. You are allowed to set the button so that you can have a help button displayed. When the help button is displayed there will be no icon appearing over the button and a different event is sent when the help button is clicked. When the help button is clicked it will act the same as any help button. I added this feature because the default form control only allows the help button when the only button in the window caption bar is a close button.

Using WinTrayButton code

This code is a little more time consuming to use, this is because the WinTrayButton is not an inherent of a component but of a native window. This means that you cannot edit the object directly using the IDE Design Mode, but you have to manually type in the code for everything. It is fairly easy to do once you know how to do it. Basically declare the object as WithEvents and edit the button's properties in the Form.Load event.

    Friend WithEvents wintraybtn As WinTrayButton = New WinTrayButton(Me)

    Private Sub Form1_Load(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles MyBase.Load
        wintraybtn.ButtonImageList = b4imagelist
        wintraybtn.ButtonMenuText = "Tray Button Menu"
    End Sub

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionHelp Button, which control clicked
Member 4292507
7:10 27 Feb '09  
I cam across this on my search for adding a Help button to the Windows Title Bar, as the standard one doesn't show when maximise/minimise buttons are visible. Using this class I have got the Help button showing fine and it even mimics the help when clicked (changes cursor to ? and allows control to be clicked). It even throws the HelpRequested event, Great! However the control that is passed to the Helprequested event in the sender object is the form and not the control clicked. Any idea how I and sort this out?
AnswerRe: Help Button, which control clicked
Thomas Stockwell
7:39 27 Feb '09  
The short answer is: it will be difficult.

The constructor of WinTrayButton you would have to add another method that would take your form type as an argument so that you can access its controls:

    Public Sub New(ByVal parent As YourForm)
AddHandler parent.HandleCreated, AddressOf Me.OnHandleCreated
AddHandler parent.HandleDestroyed, AddressOf Me.OnHandleDestroyed
AddHandler parent.TextChanged, AddressOf Me.OnTextChanged
AddHandler MinTrayBtnStateChanged, AddressOf Me.StateChange
AddHandler MinTrayBtnHelpClicked, AddressOf Me.Helpbtnclicked
Me.parent = parent

End Sub 'New
Then you would have to check with Me.parent, if it is of YourForm type, then you can also alter the helpbutton click events after you are first able to track which button is getting clicked.

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog

GeneralAwsome
bobert_smallgeek
10:31 16 Jan '09  
I was wondering if it would be possible to have the user click a button, then show the system menu, with or without transparency. I'm making a custom skiined form, and the only missing piece is the system menu. As the form doesn't have a border style, it doesn't even appear on the right-clicked taskbar button. Any help is greatly appreciated.

Thanks, bobert
GeneralRe: Awsome
Thomas Stockwell
15:12 16 Jan '09  
It is very possible to get the system menu for the window without actually having the toolbar. Unfortunately I am too busy right now to get you a code snippet, however you may want to look into WinAPI and sending messages to emulate the system menu. I believe their is another article on the CodeProject site that might delve into emulating the system menu, for that matter you could even create a new menu that emulates it.

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog

GeneralRe: Awsome
bobert_smallgeek
9:45 17 Jan '09  
Okay, thanks for your quick reply. I'll look into that even though I hate using API. Poke tongue Thanks for this awesome little program again.
Thanks,
Bobert
GeneralTooltips fron WinTrayButtons
Bill MacKenzie
12:47 16 Dec '08  
Great article Tom! But how do I add tooltip support for your WinTrayButtons like the system buttons have?
GeneralRe: Tooltips fron WinTrayButtons
Thomas Stockwell
14:51 16 Dec '08  
To be honest that is probably a bit more complicated than what it would be worth. In order to have tooltip support you would have to listen to the wndproc for mouse over events. Since .NET tooltips do not support the non-client area of the window, you would have to create the tooltips through the WinAPI. It may be possible to use .NET tooltips (within the client area, but still under the button) by manually showing the tooltip after handling the mouse over events in the wndproc. Its location would have to be hard coded.

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog

GeneralHow to insert custom button on title bar of any open external window?
Member 4140119
20:22 9 Dec '08  
Hi,

This is the application to insert custom button and menu on title bar of own window.
But I want to use same functionality with external window (insert custom button on title bar of external window (open window)). Is it same source code useful for this functionality or need to change something.

I have the open window or target windows handle and I want insert custom button on that windows title bar.


Please help me!!!!!

Thanks and Regards
Varsha
GeneralRe: How to insert custom button on title bar of any open external window?
Thomas Stockwell
6:55 10 Dec '08  
You can use this project as a general guideline for enumerating through windows, however this project will not work for external windows throughout the operating system.

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog

QuestionAdd Buttons On Every (Win 32) Window
shahid_hazoor
8:12 4 Nov '08  
I want to add buttons on every (Win 32) window when user opens.

So can you suggest me any Hook or any idea?

please help me out?

Thanks in advance

Shahid Hazoor
shahid_hazoor@hotmail.com
GeneralNot working under VISTA
Junner2006
21:15 3 Apr '08  
Absolutely no trnsparency and no buttons in VISTA SP1 !
GeneralRe: Not working under VISTA
Thomas Stockwell
5:05 4 Apr '08  
This program was written for Windows XP at the time, and Microsoft has since messed up the menu system in Vista. However, I have just used the code for another article that I wrote that uses ToolStrips/MenuStrips of .NET 2.0+, and the transparency is working for that program. The article that has mention of the transparency for the new menus can be found here[^]

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[^]

QuestionRe: Not working under VISTA
Member 1346618
0:13 13 Jun '08  
First of all: great article on title bar buttons in WXP

Is there any way to make the title bar button work in VB.NET (2.0+) on Windows Vista? Or did M$ mess up too much?

thanks in advance
Rudy
AnswerRe: Not working under VISTA
Thomas Stockwell
4:54 13 Jun '08  
I hate to say it, but M$ did a bit to much meddling with their interface for this to work under Vista. However, it is easier to customize a programs interface with Vista with the WPF of .NET 3.x.

Please be sure to vote for the article Smile

Regards,
Thomas Stockwell

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com

GeneralAny application
marcos2006
8:41 25 Jan '08  
Hi, i wonder if its possible to make a button with some very general action and add it to the title of every application launched (possibly filtering dialog boxes or toolwindows)
GeneralRe: Any application
Thomas Stockwell
8:31 23 Aug '08  
Buttons will be more difficult, but you can look into PowerMenu for how to add menu items to all windows' system menus. (Google it Smile )

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog

QuestionNice work
cristi2go
14:23 24 Aug '07  
This is a very good project, and it works just fine.
I've commented out the lines that show the icons on the button, and I see a horizontal line, like the minimize button.
I have some questions:
How can I change the text of the button ?
Is it possible to add something else than a button on the titlebar (e.g. a textbox) ?
AnswerRe: Nice work
Thomas Stockwell
16:18 24 Aug '07  
It is possible to add other items to the toolbar, but this is as close to that as I have come. I do not know how AOL has been able to add the icons/textboxes to its windows (the one thing AOL has done correctly), but it shows that it is possible.

At the moment I did a quick glance through the code (as I have not dealt with this project for ages Smile ), to add text to the actual button appearance you would have to make the rectangle for the button wider, then where the icons were drawn you would g.DrawString(...) instead of g.DrawImage(...) for the icon.

If you try to add more than a button to the window with this aproach like a textbox or something, keep in mind of all the events that you will have to handle with API commands. The button events are fairly easy to understand basically just mouseclicks, but for textboxes you may need to handle a lot more. Good luck if you try Smile .

If this doesn't help please post back.

Regards,
Thomas Stockwell

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[^]

GeneralSome bugs
zizkam
23:53 26 Jul '06  
After some time of clicking and moving mouse over the form it hangs, draws nonsenses and after a while disappears. I've looked in the Task Manager and voila - the aplication is consuming GDI objects (very fast) and after a while when it reaches a system maximum (10000) it crashes.

And second thing - the transparent menus are really really sloooooow... when I click on the menu, it draws the border and transparent window (without any text on it) and after a pretty long while (about 3 seconds) it draws the texts. The problem is not in my computer, because as the first it is high-end computer and as the second I have tried that on more computers and the behavior was exactly the same.
GeneralRe: Some bugs
1tg46
10:06 27 Jul '06  
I am still looking into the 1st bug, but the second-I am not sure if I can fix the problem. On my computer the menu does not take 3 seconds to load completely, but it does take longer than normal menus when shown (I would say less than a second to show with text but still longer than it would otherwise). At the moment I do not see a way to shorten the time for the menu.

I will coninue to look into both bugs, but I do not think I can change the second 'bug'. The first bug I believe is being caused by the excessive calling of the uxtheme API, I will try to work around the API and try to limit how many times it is being called. Hopefully that will solve the problem.

Thanks for the feedback.

Regards,
1tg46

Check out 3D Game Development with Dark Basic Professional [^]programming.

GeneralRe: Some bugs
zizkam
22:26 27 Jul '06  
Well, I don't think so. I haven't looked in the code, but I don't think that this is problem in calling the uxtheme.dll. I think that there must be some problem like not calling ReleaseDC after GetDC or something similar.
GeneralRe: Some bugs
1tg46
16:30 28 Jul '06  
I figured that out when I changed how many calls to opentheme API. I'll look into the ReleaseDC function some more. With this article or one of my other articles I was having problems with the function so I tried avoiding it, but may become a bad habit. I'll continue to look into it.

Regards,
1tg46

Check out 3D Game Development with Dark Basic Professional [^]programming.

GeneralRe: Some bugs
1tg46
13:58 2 Aug '06  
At the moment I have no software that can help in trying to fix this problem. I have altered the code for the DrawButton function so that is uses the ReleaseDC API call. The code that reduces how fast the GC builds up you can replace the function with the following code. As said his will not fix the GC problem it will just reduce slightly the effect.

Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As Int32, _
ByVal hdc As Int32) As Int32
Private Sub DrawButton(ByVal g As Graphics, ByVal state As state)
Dim windowTheme As IntPtr = openThemeData(Me.Handle, "Window")
Dim btn_width As Integer = GetSystemMetrics(SM_CXSIZE)
Dim btn_height As Integer = GetSystemMetrics(SM_CYSIZE)
Dim pos As Point
Select Case parent.FormBorderStyle
Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
pos = New Point(wnd_size.Width - ((bindex - 1) * btn_width / 1.5) - 12 - (btn_width - 18), 5)
Case FormBorderStyle.None
Case Else pos = New Point(wnd_size.Width - ((bindex - 1) * btn_width) - 12 - (btn_width - 18), 5)
End Select
' real button size
btn_width -= 2 btn_height -= 4
Dim hDC As IntPtr Select Case parent.FormBorderStyle
Case FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow
'small caption button
hDC = g.GetHdc()
If bhelpbutton = True Then Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 23, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 23, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
End Select ElseIf bimageonly = False Then Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width / 1.5, btn_height / 1.5)), IntPtr.Zero)
End Select End If ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
hDC = New IntPtr(GetWindowDC(parent.Handle.ToInt32))
g = Graphics.FromHdc(hDC) 'm.HWnd));
If bhelpbutton = False Then If Not bimagelist Is Nothing Then If bimagelist.Images.Count = 1 Then If state <> state.Disabled Then g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Else ControlPaint.DrawImageDisabled(g, bimagelist.Images(0), pos.X, pos.Y, Color.Transparent)
End If ElseIf bimagelist.Images.Count = 4 Then Select Case state
Case state.Disabled
g.DrawImage(bimagelist.Images(3), pos.X, pos.Y)
Case state.Hot
g.DrawImage(bimagelist.Images(1), pos.X, pos.Y)
Case state.Normal
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Case state.Pushed
g.DrawImage(bimagelist.Images(2), pos.X, pos.Y)
End Select ElseIf bimagelist.Images.Count > 0 And bimagelist.Images.Count <> 4 Then g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
End If End If End If g.Dispose()
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
Case FormBorderStyle.None
'draw nothing because their is not title bar to draw to
Case Else hDC = g.GetHdc
'regular size caption button
If bhelpbutton = True Then Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 23, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 23, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 23, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 23, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
End Select ElseIf bimageonly = False Then Select Case state
Case state.Normal
drawThemeBackground(windowTheme, hDC, 15, 1, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Hot
drawThemeBackground(windowTheme, hDC, 15, 2, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Pushed
drawThemeBackground(windowTheme, hDC, 15, 3, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
Case state.Disabled
drawThemeBackground(windowTheme, hDC, 15, 4, New RECT(New Rectangle(pos.X, pos.Y, btn_width, btn_height)), IntPtr.Zero)
End Select End If ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
hDC = New IntPtr(GetWindowDC(parent.Handle.ToInt32))
g = Graphics.FromHdc(hDC) 'm.HWnd));
If bhelpbutton = False Then If Not bimagelist Is Nothing Then 'offset x, y values to center image in button
pos.Offset(Math.Sqrt(btn_width) - 1, Math.Sqrt(btn_height) - 1)
If bimagelist.Images.Count = 1 Then If state <> state.Disabled Then g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Else ControlPaint.DrawImageDisabled(g, bimagelist.Images(0), pos.X, pos.Y, Color.Transparent)
End If ElseIf bimagelist.Images.Count = 4 Then Select Case state
Case state.Disabled
g.DrawImage(bimagelist.Images(3), pos.X, pos.Y)
Case state.Hot
g.DrawImage(bimagelist.Images(1), pos.X, pos.Y)
Case state.Normal
g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
Case state.Pushed
g.DrawImage(bimagelist.Images(2), pos.X, pos.Y)
End Select ElseIf bimagelist.Images.Count > 0 Then g.DrawImage(bimagelist.Images(0), pos.X, pos.Y)
End If End If End If g.Dispose()
ReleaseDC(Me.Handle.ToInt32(), hDC.ToInt32())
End Select System.GC.GetTotalMemory(True)
End Sub 'DrawButton


Regards,
1tg46

Check out 3D Game Development with Dark Basic Professional [^]programming.

GeneralSystem.InvalidOperation Exception
hannesHTG
3:56 26 Jun '06  
Hi!
I get a System.InvalidOperation Exception when I click on the Stylelist ListBox.

What should I do to fix it ¿
GeneralRe: System.InvalidOperation Exception
1tg46
14:44 15 Jul '06  
Do you have the proper system requirements. This articles code can only be run on WinXP or higher operating system. If you do have WinXP or higher then would you mind giving me the stacktrace for the exception. This will help me isolate where the problem is occuring.

Regards,
1tg46

Check out 3D Game Development with Dark Basic Professional [^]programming.


Last Updated 7 Feb 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010