473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Any way to custom draw a title bar?

How would you go about custom drawing the title bar of a form? I'd like
to change it so that I can add different colors to my title and also
change how the close button works (since I override it and cause the
form to minimize).

Thanks in advance,
Benny
Nov 17 '05 #1
2 16231
Benny,

You will have to override the WndProc method on your form. In there,
you will want to handle the WM_NCPAINT message, which is sent when the frame
(including the title bar) needs to be painted.

If you call the base method of WndProc, it will draw the frame, and then
you can draw over the frame, or, you can paint the whole thing yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:ez**************@tk2msftngp13.phx.gbl...
How would you go about custom drawing the title bar of a form? I'd like
to change it so that I can add different colors to my title and also
change how the close button works (since I override it and cause the form
to minimize).

Thanks in advance,
Benny

Nov 17 '05 #2
I'm now overriding wndproc and handling the wm_ncpaint by letting base
do it first and then drawing over the top... This works the first time
the program draws the close button but after that it doesn't work...
Note: I'm just drawing a big white box right now to get the
functionality in - why is the close button drawing outside of
wm_ncpaint?... Here's the code:

protected override void WndProc(ref Message m)
{
switch ( m.Msg )
{
case (int) MSG.WM_NCPAINT:
base.WndProc( ref m );
Main_OnNcPaint( ref m );
return;
}
}

private void Main_OnNcPaint ( ref Message m )
{
Debug.WriteLine("drawing");
// If I use GetDCEx, the program crashes on the Graphics
// .FromHdc Line - GetDCEx returns 0?
//IntPtr hdc = User32.GetDCEx( m.HWnd, m.WParam,
((uint)DCX_FLAGS.DCX_WINDOW)|((uint)DCX_FLAGS.DCX_ INTERSECTRGN) );

IntPtr hdc = User32.GetWindowDC(m.HWnd);
Graphics g = Graphics.FromHdc(hdc);

int CaptionHeight = Bounds.Height - ClientRectangle.Height; //Titlebar
Size CloseButtonSize = SystemInformation.CaptionButtonSize;
int X = Bounds.Width - CloseButtonSize.Width;
int Y = 6;

// ControlPaint causes the program to not use XP styles anymore :(
//ControlPaint.DrawButton(g, X, Y, 15, 15, ButtonState.Normal);

// Fill a rectangle instead
g.FillRectangle(SystemBrushes.Window, X, Y, CloseButtonSize.Width,
CloseButtonSize.Height);
//g.Dispose();
User32.ReleaseDC(m.HWnd, hdc);

m.Result = IntPtr.Zero;

}



Nicholas Paldino [.NET/C# MVP] wrote:
Benny,

You will have to override the WndProc method on your form. In there,
you will want to handle the WM_NCPAINT message, which is sent when the frame
(including the title bar) needs to be painted.

If you call the base method of WndProc, it will draw the frame, and then
you can draw over the frame, or, you can paint the whole thing yourself.

Hope this helps.

How would you go about custom drawing the title bar of a form? I'd like
to change it so that I can add different colors to my title and also
change how the close button works (since I override it and cause the form to minimize).

Thanks in advance,
Benny

Nov 27 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Florida Draw | last post by:
------=_NextPart_000_0012_1D5428A2.65C196F8 Content-Type: text/plain Content-Transfer-Encoding: 8bit Sign-up for the FREE Holiday Giveaway Draw You must register to be eligible for the draw....
0
by: Steve | last post by:
I have created a transparent custom drawn treeview in c#(using lots of native code as well) that has a bitmap for its background. As well as that, I have created a custom highlight that is a...
5
by: Brian Keating EI9FXB | last post by:
Hello there, Wonder can anyone point me in the correct direction? I would like to change the standard list view control so that i can have alternated rows in a different color, i.e. white grey...
3
by: Angapparaj K via .NET 247 | last post by:
Hi, Iam trying to create a custom tree view control in thich i needto display images for some of the nodes. The images need on theright side of the nodes. Is there any way to do this...
15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
4
by: Alvo von Cossel I | last post by:
hi, i have been asked to make a good-looking app for a friend. i have an options form with a big tabstrip in it. 1. how can i customize it e.g. change from the standard system style...
2
by: Furer Ramon | last post by:
hi every one please i need know how to create a custom title bar like writing on title bar and change the look of maximize button and close button and so on using ..net framework Greets R....
2
by: eljainc | last post by:
Hello, I would like my program to display the caption on the form (top of form on title bar) in a different font. I would ideally like to have one part of the form caption in one font, and...
2
by: ahmed.maryam | last post by:
Hello Everyone, I designed a custom control that is entirely covered by a picture box. I then dragged this custom control onto a windows form application (called main) and I need to handle mouse...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.