如何在VB.NET中更改winform标题栏的背景颜色? [英] How to change background color of titlebar of winform in VB.NET?

查看:142
本文介绍了如何在VB.NET中更改winform标题栏的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在winform中更改标题栏的背景颜色



我尝试了什么:



我已经使用此代码在表单上设置图形但是当我使用alt + tab移动到另一个窗口时,图形将从表单中删除



[DllImport(user32.dll)]

static extern int ReleaseDC(IntPtr hWnd,IntPtr hDC);



[DllImport(User32.dll)]



private static extern IntPtr GetWindowDC(IntPtr hWnd);



protected override void WndProc(ref System.Windows.Forms.Message m)

{

const int WM_NCPAINT = 0x85;

base。 WndProc(参考);



if(m.Msg == WM_NCPAINT)

{



IntPtr hdc = GetWindowDC(m.HWnd);

if((int)hdc!= 0)

{

图形g = Graphics.FromHdc( hdc);

矩形screenRectangle = RectangleToScreen(this.ClientRectangle);

int titleHeight = screenRectangle.Top - this.Top;

Rectangle rect = new Rectangle(0,0,this.Width-100,30);

g.FillRectangle(Brushes.Green,rect);

g.Flush();

ReleaseDC(m.HWnd,hdc);

}



}



}

I want to change the background color of titlebar in winform

What I have tried:

I have used this code to set graphic on form but when I am doing alt+tab for moving to another window then graphic will remove from the form

[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

[DllImport("User32.dll")]

private static extern IntPtr GetWindowDC(IntPtr hWnd);

protected override void WndProc(ref System.Windows.Forms.Message m)
{
const int WM_NCPAINT = 0x85;
base.WndProc(ref m);

if (m.Msg == WM_NCPAINT)
{

IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle);
int titleHeight = screenRectangle.Top - this.Top;
Rectangle rect = new Rectangle(0, 0, this.Width-100, 30);
g.FillRectangle(Brushes.Green, rect);
g.Flush();
ReleaseDC(m.HWnd, hdc);
}

}

}

推荐答案

说实话,因为Win8至少你如果不完全删除所有标题栏gubbins并自己重新创建它,可能无法做到。问题是标题栏有两种状态Active和Inactive,它的条形颜色由它控制。您可以通过 ApplicationViewTitleBar类 [ ^ ]但我不要认为它在Winforms中是可能的。
To be honest, since Win8 at least you probably can't do it without removing all the title bar gubbins completely and recreating it yourself. The problem is that the title bar has two states Active and Inactive, and it's bar colours are controlled by that. You can do it in a UWP app via the ApplicationViewTitleBar Class[^] but I don't think it's going to be possible in Winforms.


最简单的方法是覆盖 WndProc方法 [ ^ ],请参阅: c# - 更改WinForm中标题栏的颜色 [ ^ ]



详情请见: Winforms SkinFramework [ ^ ]
The "simplest" way is to override WndProc method[^], see: c# - Changing the color of the title bar in WinForm[^]

For further details, please see: Winforms SkinFramework[^]


我试过这个将图形放在表单标题栏上,但当我在做alt + tab时,图形将被删除
I have tried this to put graphic on a form titlebar but when I am doing alt+tab the graphic will be removed from that


这篇关于如何在VB.NET中更改winform标题栏的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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