Changing the color of the title bar in WinForm

谁都会走 提交于 2019-11-28 04:40:23
Aravind

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);
        }
    }
}
Asif Mushtaq

What you can do is set the FormBorderStyle property to None and do what ever you want with the form using GDI.

Ria

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.

This is easy to do:

  1. Right-click on the desktop, and select "Personalize".

  2. Click on the "Window Color" tile at the bottom of the screen.

  3. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!