Determine Label Size based upon amount of text and font size in Winforms/C#

前端 未结 11 1767
半阙折子戏
半阙折子戏 2020-11-30 01:27

I\'d like to know if there\'s a better approach to this problem. I want to resize a label (vertically) to accomodate certain amount of text. My label has a fixed width (abou

11条回答
  •  感动是毒
    2020-11-30 02:23

    I posted a user control which solves this problem in the accepted answer here: Autoscale Font in a TextBox Control so that its as big as possible and still fits in text area bounds

    The control extends RichTextBox. It has a method: ScaleFontToFit that will automatically resize the font to make all the text fit.

    Neat thing is it respects the multiline property. If it's true it allows words to wrap, Otherwise it doesn't.

提交回复
热议问题