Is it possible to change the color of the title bar of a WinForm in C#?
__________________________
[Form1_______________-|[]|X] <- I want to change the color of this
| |
| |
| |
|__________________________|
I solved this problem. This is the code:
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_NCPAINT = 0x85;
if (m.Msg == WM_NCPAINT)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
g.FillRectangle(Brushes.Green, new Rectangle(0, 0, 4800, 23));
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
Use Drawing Custom Borders in Windows Forms project from CodePlex. This project is a small library that extends Windows Forms with the ability to customize the windows' non-client area.
What you can do is set the FormBorderStyle
property to None
and do what ever you want with the form using GDI.
This is easy to do:
Right-click on the desktop, and select "Personalize".
Click on the "Window Color" tile at the bottom of the screen.
Choose your new color.
If your computer is configured to use the Aero theme, you can choose from one of the standard colors or mix one of your own.
If you're using the Classic theme, you'll see a "Window Color and Appearance" dialog you can use to set colors. Click on the title bar the sample desktop, the one called "Active Window", and then use the "Color 1" and "Color 2" drop-down boxes to pick a new color.
I can only assume this is what you meant, because there is absolutely no excuse to change only the color of your application's title bar. There's a reason that this is a system-wide setting.
Always obey the user's preferences. If they wanted your title bar to be a different color, they would choose a different color.