Adding buttons to the form's title bar

  • Thread starter Thread starter Picho
  • Start date Start date
P

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.
 
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
 
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();

}

}
 
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)
 
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
 
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
 
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
 
Back
Top