C# windows - Auto increment font size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leoiser
    New Member
    • Jul 2007
    • 41

    C# windows - Auto increment font size

    I want to get the maximum font size that can fit to a button.I am loading a Button to a panel.its width and height will vary(dynamicall y based on some calculations).I want to increase to the maximum font size.

    For example :- Lets assume that Button size is (100,60) and Text is "AC" (only two letters will come). what should be the maximum font size that can fit in this button. if Button size is (150,250) what should be maximum font size that can fit in this button.

    Please advice

    Thanks,
    Ebin
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Try taking a look at the MeasureString method on the Graphics object.



    You should be able to measure the size of the string that goes in the button with various fonts and see which will fit. In order to access the Graphics object for the button, you may have to override the button's OnPaint method and when you change text, call myButton.Invali date() to update.

    Comment

    Working...