here's my solution.... I think it does everything you
described in your posting but one thing... If the user
changes the skin... your app will still show the normal
title bar. If this is okay... read on.
This idea can be wrapped up in a new form class so that
you can use it for the MDI or MDIChild forms.
1) create a normal form in the designer
2) remove its Maximize, minimize, controlBox and title
text. This will result in a form without a titlebar.
3) set its border style to sizeable.
4) add 2 picture boxes; pbtitlebar and pbIcon
5) set the dock property of the pbtitlebar to "top".
6) set the image property of the pbtitlebar to a bitmap
of the solid part of the title bar of a typical window.
7) make sure that the height of pbtitlebar is exactly the
same as the bitmap. Set the SizeMode to StretchImage
(this will cause some pixelation.. to avoid that you can
create a very long title bar for the largest screen you
can imagine... alternatively set the SizeMode to
StrechImage if the width of the pbtitlebar get longer
that 21 inch or whatever).
8) set the image of the pbicon to your application icon
and locate it in the upper left corner of the window.
Make sure to "Bring" it "to front";
9) run your program and resize the form... it clearly
behaves as though you have a title bar with an icon ,
but no text or minimum/maximum/close button.
10) create your buttons and position them on the
new "Title bar";
11) in the paint event of the pbTitleBar, write
instructions to locate the buttons programatically
correctly... i.e.
this.btnClose.left = pbtitlebar.right -
this.btnClose.width - 5;
this.btnMax.left = this.btnClose.left -
this.btnMax.width - 5;
etc;
12) add the button click handlers
13) After the click for each button make sure that the
focus is transferred to a control on the form.
14) you can simulate the active/inactive windows by
changing the image of the picture boxes (dark blue for
active and faint blue for inactive.
15) you can also program the drag event of the pbtitlebar
to help moving the windows around on the screen.
16) you can get the window's title written to the
pbTitleBar by something like this:
private void ShowTitle()
{
System.Drawing.Graphics g =
this.pbTitleBar.CreateGraphics();
System.Drawing.Font font = new System.Drawing.Font
("Times New Roman", 12);
System.Drawing.PointF pos = new System.Drawing.PointF
(this.pictureBox2.Width + 5, this.pictureBox2.Top );
System.Drawing.Brush brush = new
System.Drawing.SolidBrush(System.Drawing.Color.Whi te);
g.DrawString ("windows title", font, brush, pos);
}
You need to call ShowTitle in the form_paint and
pbTitleBar_Paint.
let me know if you have any problems with this.
good luck
Nasser.
-----Original Message-----
Hi all,
Is there any .NET way (I am not rulling out API usage)
to add button(s) to aform'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 theclient area - no visible way to paint on the title bar.
Since my application is MDI parent and children (even
though i would love ageneric solution), I also tried something silly that
worked: adding a buttonmember to the form (actually a derived class of form),
and in theconstructor, adding it to the MDIParent.Controls
property. after doing so,all that is left is controling the button's position
accurding to the formposition 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 formsbecause otherwise they all appear on top of every other
element. the secondproblem was drawing the button when minimized (no focus
when moving aminimized mdi child form - thus, unable to determine if
to show or hide thebutton) and drawing the button when maximized - this
seems all and allimpossible to do - no way to place even that "super-
button" on top of themaximized title bar.
any help would be great,
Picho.
.