gpt4 book ai didi

c# - 改变WinForm中标题栏的颜色

转载 作者:IT王子 更新时间:2023-10-29 04:02:47 26 4
gpt4 key购买 nike

是否可以在 C# 中更改 WinForm 标题栏的颜色?

          __________________________
[Form1_______________-|[]|X] <- I want to change the color of this
| |
| |
| |
|__________________________|

最佳答案

我解决了这个问题。这是代码:

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

关于c# - 改变WinForm中标题栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11862315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com