问题描述
Hello All,
我正在使用以下代码更改标题栏的颜色,但是当我最大化我的或调整表单大小时,控制框不会出现。当我鼠标悬停然后再次出现控制框时,任何人都知道下面的代码有什么问题?
[DllImport(user32.dll)]
static extern int ReleaseDC(IntPtr hWnd,IntPtr hDc);
[DllImport(User32.dll)]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
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);
SolidBrush b =新的SolidBrush(Color.FromArgb( 0,116,212));
g.FillRectangle(b,new Rectangle(0,0,4800,30));
g.Flush();
ReleaseDC(m.HWnd,hdc);
}
}
}
private void Form1_Load(object sender,EventArgs e)
{
this.BackColor = Color.FromArgb(214,236,246);
this.StartPosition = FormStartPosition.CenterScreen;
}
我尝试了什么:
我试过上面的代码。还有很多其他的代码,但是我遇到了与控制盒相同的问题。
Hello All,
I am changing color of title bar using following code but when I maximise my or resize form then control box not appear. when I mouse over then again control box will appear so any one know what is the issue in following code?
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
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);
SolidBrush b = new SolidBrush(Color.FromArgb(0, 116, 212));
g.FillRectangle(b, new Rectangle(0, 0, 4800, 30));
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.FromArgb(214, 236, 246);
this.StartPosition = FormStartPosition.CenterScreen;
}
What I have tried:
I tried above code. and many other code but I face same issue with control box.
推荐答案
这篇关于C#窗体中的控制框(最大化,最小化和关闭按钮)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!