【问题标题】:How to change title bar font in win apps by C#?如何通过 C# 更改 win 应用程序中的标题栏字体?
【发布时间】:2012-03-22 21:54:27
【问题描述】:

如何通过 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);

【问题讨论】:

    标签: c# winforms titlebar


    【解决方案1】:

    在 Vista 和 Windows 7 上,您需要禁用 Aero 才能使代码正常工作。

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

    【讨论】:

      【解决方案2】:

      我不知道是否可以,因为您只能编辑文本而不能编辑标记。

      我认为它只是使用 windows 使用的字体大小...

      【讨论】:

      • 我认为应该有一种方法可以使用 Windows API。
      • 可能是,如果是这样,我不知道......这正是我的想法。
      猜你喜欢
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 2016-07-29
      相关资源
      最近更新 更多