How to change title bar font in win apps by C#?

眉间皱痕 提交于 2019-12-01 05:27:22

问题


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

回答1:


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?




回答2:


I don't know if it is possible since you can only edit the text but not the markup.

I think it just uses the font-size that windows uses...



来源:https://stackoverflow.com/questions/9566443/how-to-change-title-bar-font-in-win-apps-by-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!