0

A simple question, just as stated in the title... How can I get the width of the title on a form?

I want to resize a form to match the width of text in the title bar.

enter image description here

Arvo Bowen
  • 4,524
  • 6
  • 51
  • 109
  • You could try using [MeasureString](https://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx), passing the text and `SystemFonts.CaptionFont`. – Blorgbeard Oct 17 '17 at 21:53
  • 2
    Have you ever seen a window with such behavior? I believe it's possible, but not a good idea. Anyway, here is a [duplicate](https://stackoverflow.com/q/18089280/3110834). – Reza Aghaei Oct 17 '17 at 21:55
  • 1
    Please be aware that `MeasureString` is a "fuzzy" calculation - it's not accurate and there's no way to adjust for the inaccuracy. – Enigmativity Oct 17 '17 at 22:05
  • Yea @RezaAghaei a messagebox (I'm not only checking the titlebar, that's just the one I didn't know how to measure). ;) And that was EXACTLY what I needed, I looked around for a similar question but could not find one. Thanks for pointing it out guys! – Arvo Bowen Oct 17 '17 at 22:17
  • I feel @Enigmativity needs some credit for flagging the dup pointing me to the other question as well so +1 from me on that comment too. ;) – Arvo Bowen Oct 17 '17 at 22:18

0 Answers0