473,769 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16294
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.co m

"Benny Raymond" <be***@pocketro cks.com> wrote in message
news:ez******** ******@tk2msftn gp13.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_FLAG S.DCX_WINDOW)|( (uint)DCX_FLAGS .DCX_INTERSECTR GN) );

IntPtr hdc = User32.GetWindo wDC(m.HWnd);
Graphics g = Graphics.FromHd c(hdc);

int CaptionHeight = Bounds.Height - ClientRectangle .Height; //Titlebar
Size CloseButtonSize = SystemInformati on.CaptionButto nSize;
int X = Bounds.Width - CloseButtonSize .Width;
int Y = 6;

// ControlPaint causes the program to not use XP styles anymore :(
//ControlPaint.Dr awButton(g, X, Y, 15, 15, ButtonState.Nor mal);

// Fill a rectangle instead
g.FillRectangle (SystemBrushes. Window, X, Y, CloseButtonSize .Width,
CloseButtonSize .Height);
//g.Dispose();
User32.ReleaseD C(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
1945
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. Fill out this form to register and you may be eligible for our monthly draw.
0
334
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 different shape than the default treeview selection highlight. I catch NM_CUSTOMDRAW and in the CDDS_PREPAINT draw stage, I draw the bitmap and return the result CDRF_NOTIFYITEMDRAW In the CDDS_ITEMPREPAINT drawstage I set the background mode to...
5
12494
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 white grey And I'd also like to change the color or the first colmn. What is the best approach for same? thanks Brian
3
19459
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 besideshandling the windows notification messages? even if possibleonly thro windows messages, can some one guide me to some csharp code implementing something similar. yours, K.Angapparaj -------------------------------- From: Angapparaj K
15
10948
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 great. But I now want to show a different tooltip for every day. For now I found out that I can add a tooltip for the entire custom control
4
2325
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 tabcontrol to what i want? 2. if #1 isnt possible to do, what would be the best way to make something look like a tabstrip?
2
2424
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. Furer
2
5111
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 another part in a standard (i.e. Arial) font. How do I go about doing this? It is probably an an override of the standard form or a custom draw routine for the caption.
2
3258
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 events in my main application. Specifically, when a user double clicks on my custom control I need to draw something on another picture box located in my main application. I'm going to attempt to draw the scenario because I think it will
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.