Search code examples
c#windowsformstitlebar

C# - How to Determine a Form's Title bar font?


I want to create a form that is wide enough to show the title bar string, which is dynamic. To compute the string's text width, I need to know the title bar font. How do I query it?


Solution

  • You can use SystemFonts.CaptionFont property:

    Gets a Font that is used to display text in the title bars of windows.

    Sample usage:

    using System.Drawing;
    
    var font = SystemFonts.CaptionFont;