改变WinForm的标题栏的颜色

改变WinForm的标题栏的颜色

本文介绍了改变WinForm的标题栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变一个WinForm的标题栏的颜色在C#?

  __________________________
         [Form1中_______________- | [] | X]<  - 我想改变这种颜色
         | |
         | |
         | |
         | __________________________ |
 

解决方案

我解决了这个问题。这是code:

  [的DllImport(User32.dll中,字符集= CharSet.Auto)
公共静态外部INT ReleaseDC(IntPtr的的HWND,IntPtr的HDC);

[的DllImport(User32.dll中)]
私人静态外部的IntPtr GetWindowDC(IntPtr的的HWND);

保护覆盖无效的WndProc(参考消息M)
{
    base.WndProc(REF米);
    const int的WM_NCPAINT = 0x85未;
    如果(m.Msg == WM_NCPAINT)
    {
        IntPtr的HDC = GetWindowDC(m.HWnd);
        如果((int)的HDC!= 0)
        {
            图形G = Graphics.FromHdc(HDC);
            g.FillRectangle(Brushes.Green,新的Rectangle(0,0,4800,23));
            g.Flush();
            ReleaseDC(m.HWnd,HDC);
        }
    }
}
 

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

这篇关于改变WinForm的标题栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:36