微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何用C#更改win apps中的标题栏字体?

我如何通过C#在 Windows应用程序中更改窗体的标题栏字体?

我发现这段代码但没有工作,也没有绘制标题栏:
我怎样才能做到这一点?
谢谢大家

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

解决方法

在Vista和Windows 7上,您需要禁用Aero才能使代码生效.

看看我提供给以下问题的答案
How to add an extra button to the window’s title bar?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐