如何通过C#来改变在Win应用标题栏字体? [英] How to change title bar font in win apps by C#?
本文介绍了如何通过C#来改变在Win应用标题栏字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何通过C#改变形式的标题栏字体在windows应用程序
我发现这个代码,但没有工作,没有图纸标题栏:
我怎样才能做到这一点?
感谢所有
保护覆盖无效的WndProc(参考消息MSG)
{
群。的WndProc(参考MSG);
const int的WM_NCPAINT = 0x85未;
如果(msg.Msg == WM_NCPAINT)
{
this.Text =; //删除原来的标题文字
IntPtr的HDC = GetWindowDC(msg.HWnd);
图形G = Graphics.FromHdc(HDC);
字体英尺=新的字体(宋体,16);
g.DrawString(你好世界冠军,FT,Brushes.Red,新的PointF(20.0f,0.0));
ReleaseDC(msg.HWnd,HDC);
}
}
函数[DllImport(User32.dll中)]
私人静态外部的IntPtr GetWindowDC(IntPtr的的hWnd);
函数[DllImport(User32.dll中)]
私人静态外部INT ReleaseDC(IntPtr的的HWND,IntPtr的HDC);
解决方案
在Vista和Windows 7,你需要禁用Aero的的代码工作。
看看我下面的问题
的如何添加一个额外的按钮,窗口的标题栏?
how i change title bar font of form in windows application by C# ?
i found this code but not working and doesn't drawing titlebar: how can i do this? thanks all
protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
const int WM_NCPAINT = 0x85;
if (msg.Msg == WM_NCPAINT)
{
this.Text = "";// remove the original title text
IntPtr hdc = GetWindowDC(msg.HWnd);
Graphics g = Graphics.FromHdc(hdc);
Font ft = new Font("Arial", 16);
g.DrawString("Hello World title", ft, Brushes.Red, new PointF(20.0f, 0.0f));
ReleaseDC(msg.HWnd, hdc);
}
}
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("User32.dll")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
解决方案
On Vista and Windows 7 you will need to disable Aero for the code to work.
Take a look at the answer I provided to the following question How to add an extra button to the window's title bar?
这篇关于如何通过C#来改变在Win应用标题栏字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文