Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Adding buttons to the form's title bar
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.drawing.


Picho
Hi all,

Is there any .NET way (I am not rulling out API usage) to add button(s) to a
form's title bar?

I found some non-.NET solutions that did actually work in VB6 but not in the
..NET forms...

I tried painting, but the paintaing area provided by the form is only the
client area - no visible way to paint on the title bar.

Since my application is MDI parent and children (even though i would love a
generic solution), I also tried something silly that worked: adding a button
member to the form (actually a derived class of form), and in the
constructor, adding it to the MDIParent.Controls property. after doing so,
all that is left is controling the button's position accurding to the form
position and size. since the button is located on the MDIParent it has a
"Z-Order" which is higher than the form, and therefor drawn on top of it.
Only two problems with that: I had to hide the buttons of un-focused forms
because otherwise they all appear on top of every other element. the second
problem was drawing the button when minimized (no focus when moving a
minimized mdi child form - thus, unable to determine if to show or hide the
button) and drawing the button when maximized - this seems all and all
impossible to do - no way to place even that "super-button" on top of the
maximized title bar.

any help would be great,

Picho.

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Eric Cadwell
I wrote a solution for VB6 and I can say that there's no simple way to do
it. The best you can do is override the WndProc method of the form and
listen for NC_PAINT events. Paint your button onto the non-client area. Then
listen for mouse events and respond accordingly.

There wasn't much of a market for this, so I haven't ported my VB6 code to
..NET

HTH;
Eric Cadwell
http://www.origincontrols.com

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Eric Cadwell
That is WM_NCPAINT events.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Picho
well this seems the problem....

ho do i paint on non-client area?

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Eric Cadwell
Try Graphics.FromHdc.

HTH;
Eric Cadwell
http://www.origincontrols.com

Reply to this message...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
    
Picho
just did

it says "out of memory"...
only thing i can think of is maybe i got the "WM_NCPAINT" enum value wrong?

protected override void WndProc(ref Message message)

{

base.WndProc(ref message);

if (message.Msg==0x0085)

{

Graphics gfx = Graphics.FromHdc(message.WParam);

gfx.DrawLine(Pens.Black, 0,0, 20,20);

gfx.Dispose();

}

}

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Eric Cadwell
const int WM_NCPAINT = 0x85;

Reply to this message...
Vote that this is a GOOD answer...
 
Google Docs… no.
Twitter Elite
 
    
Picho
well I cant see whats wong then...
did you look at he code i sent?
(throws same exception if I use 0x85 instead of 0x0085)

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Eric Cadwell
Ah yes, the error is in the way you get the DC. Try this instead:

IntPtr hDC = GetWindowDC(message.HWnd);
Graphics graph = Graphics.FromHdc(hDC);

0x85 and 0x0085 are the same.

HTH;
Eric Cadwell
http://www.origincontrols.com

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Picho
Tahnks!

It works great!

attached a capture of it...

only problem now, is when I use this form as an mdi child, and maximize it,
it doesnt draw...
guess that has to do with the parent form drawing right?

any solution for that?

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Eric Cadwell
Looks good! I'm having issues with the frame not painting on WM_ACTIVATE
and/or WM_PAINT. Are you listening for all of them?

I'll try MDI next, I tried to monkey with MDI and WM_NCCALCSIZE, but
something went wrong.

HTH;
Eric Cadwell
http://www.origincontrols.com

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Picho
Solved the MDI Issue.

generaly speaking, I am listening to WM_NCPAINT and WM_NCACTIVATE (left out
the mouse events naturally)
It doesnt give me any pain (had to figure out the WM_NCACTIVE though...)
I guess there is much more to do in terms of regions etc and since I am new
to Messages and drawing, I didnt do anything at all in that sence.

The MDI thing was solved by giving the MDI parent the same abilities and
comunicating using all the MDI properties (like active mdi child etc).

If this helps you, I'll send you the source code.

And hey,

Thanks alot for your help!

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Eric Cadwell
Looks awesome! Got the MDI stuff, but WM_NCACTIVATE is still killing me.
When your app loses focus, does the button diappear? I'm doing an Invalidate
(and painting in response to WM_PAINT), but that causes a bit of a flicker
cause I'm currently repainting the whole window.

I would like to view the that part of the source. If you don't mind just
remove the "ns." from my email address.

-Eric

Reply to this message...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
    
Picho
no prob. email on the way.

im sending just the inherited form class, the mdi parent code is the same -
just invokes a method on the child form that raises my "button click" event.

i did none of what you said on validating.. dont know what that means...
"who dares wins" lol

"Eric Cadwell" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Google Docs… no.
Twitter Elite
 
    
Martin Hinshelwood
Hi,

Can someone help me. I am new to the capturing windows messages and can't even get your black line to draw consistantly.

Case Win32.WM.NCPAINT, Win32.WM.NCACTIVATE, Win32.WM.NCCREATE
Dim gfx As Graphics = Graphics.FromHdc(Win32.GetWindowDC(m.HWnd))
gfx.DrawLine(Pens.Black, 0, 0, 20, 20)
gfx.Dispose()

I get the black line the first time the app is loaded and the form displayed, but after that it never apiers again??

--------------------------------
From: Martin Hinshelwood
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Martin Hinshelwood
Hi,

Can someone help me. I am new to the capturing windows messages and can't even get your black line to draw consistantly.

Case Win32.WM.NCPAINT, Win32.WM.NCACTIVATE, Win32.WM.NCCREATE
Dim gfx As Graphics = Graphics.FromHdc(Win32.GetWindowDC(m.HWnd))
gfx.DrawLine(Pens.Black, 0, 0, 20, 20)
gfx.Dispose()

I get the black line the first time the app is loaded and the form displayed, but after that it never apiers again??

--------------------------------
From: Martin Hinshelwood
Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Martin Hinshelwood
Hi,

Can someone help me. I am new to the capturing windows messages and can't even get your black line to draw consistantly.

Case Win32.WM.NCPAINT, Win32.WM.NCACTIVATE, Win32.WM.NCCREATE
Dim gfx As Graphics = Graphics.FromHdc(Win32.GetWindowDC(m.HWnd))
gfx.DrawLine(Pens.Black, 0, 0, 20, 20)
gfx.Dispose()

I get the black line the first time the app is loaded and the form displayed, but after that it never apiers again??

--------------------------------
From: Martin Hinshelwood
Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Martin Hinshelwood
Hi,

Can someone help me. I am new to the capturing windows messages and can't even get your black line to draw consistantly.

Case Win32.WM.NCPAINT, Win32.WM.NCACTIVATE, Win32.WM.NCCREATE
Dim gfx As Graphics = Graphics.FromHdc(Win32.GetWindowDC(m.HWnd))
gfx.DrawLine(Pens.Black, 0, 0, 20, 20)
gfx.Dispose()

I get the black line the first time the app is loaded and the form displayed, but after that it never apiers again??

--------------------------------
From: Martin Hinshelwood
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Martin Hinshelwood
Hi,

Can someone help me. I am new to the capturing windows messages and can't even get your black line to draw consistantly.

Case Win32.WM.NCPAINT, Win32.WM.NCACTIVATE, Win32.WM.NCCREATE
Dim gfx As Graphics = Graphics.FromHdc(Win32.GetWindowDC(m.HWnd))
gfx.DrawLine(Pens.Black, 0, 0, 20, 20)
gfx.Dispose()

I get the black line the first time the app is loaded and the form displayed, but after that it never apiers again??

--------------------------------
From: Martin Hinshelwood
Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
 
System.Drawing.Graphics
System.Drawing.Pens
System.IntPtr




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734