C# windws- 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(dynamically 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
-
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(dynamically 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
May following code snip helps you
Graphics g1 = button1.CreateGraphics();
for (int i = 1; i < 100; i++) { SizeF size1 = g1.MeasureString(button1.Text, new Font("Verdana", i, FontStyle.Regular)); if (size1.Width > button1.Width) { button1.Font = new Font("Verdana", i - 1, FontStyle.Regular); break; } }
:)
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please
-
May following code snip helps you
Graphics g1 = button1.CreateGraphics();
for (int i = 1; i < 100; i++) { SizeF size1 = g1.MeasureString(button1.Text, new Font("Verdana", i, FontStyle.Regular)); if (size1.Width > button1.Width) { button1.Font = new Font("Verdana", i - 1, FontStyle.Regular); break; } }
:)
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim So Smile Please