C#窗体中的控制框(最大化,最小化和关闭按钮)问题 [英] Controlbox(maximise, minimise and close button) issue in C# windows form

查看:60
本文介绍了C#窗体中的控制框(最大化,最小化和关闭按钮)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

简单:你做的基本NCPaint,我怀疑它处理控制盒的子控件和相关的控制,然后用你的新颜色涂上它们。

我建议你不要试图只绘画它,而是要看一下整个表格应用皮肤。有几种方法可以做到这一点,但大多数都需要花钱:

皮肤引擎。 C ++,C#,Visual Basic皮肤 [ ^ ]

Windows Forms .NET扩展的VisualStyler [ ^ ]

Google会为您找到更多信息:剥皮c# - Google搜索 [ ^ ]
Simple: you do the base NCPaint which I suspect handles it's sub controls for the Control Box and related controls and then paint over them with your new colour.
I would suggest that instead of trying to just paint it you have a look at applying a Skin to the whole form. There are several ways to do that, but most do cost money:
Skin engine. C++, C#, Visual Basic skinning[^]
VisualStyler for Windows Forms .NET extension[^]
Google will find you more: skinning c# - Google Search[^]


这篇关于C#窗体中的控制框(最大化,最小化和关闭按钮)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆