views:

943

answers:

2

How do I draw a toolbar on the titlebar of a C# winforms window in windows vista? I have a window where it works, except when the window is unminimized/unmaximized it increases in size by about 16x32px. If possible, please provide code examples.

+1  A: 

The only way to effectively do it is to handle the WM_NCPAINT message when you override the WndProc method for the Form.

Passing to the base implementation of WndProc will cause the windows frame to be painted, but at that point, you would be responsibile for painting your toolbar elements on the title bar.

You will also want to handle all the other WM_NC* messages as well, which will allow you to process button clicks and the like (which you will need to handle events for your painted controls).

casperOne
Can you provide example code as I am new to c#.
duckblaster
A: 

I've been looking around for the same problem, because I wanted to code a ribbon bar with that big button in the upper left corner... The only good source I found was at CodeProject and this one and another one.

Peter
I had looked at those, and am using the one from http://www.codeproject.com/KB/dialog/AeroNonClientAreaButtons.aspx, but have problems with the size of the window expanding every time it is unminimized/unmaximized.
duckblaster
You may need to manually reset the size of the form to overcome this.
lucifer