Click here to Skip to main content
14,428,415 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,

I have a Label in my C# program. It is AutoSize property is false and size is 112, 98 and font details are Microsoft Sans Serif, 21.75pt, style=Bold.
Here I need is to create this label to change it's font size dynamically according to text I input, to ensure every letter I input to this label is visible.

I need a peace of advise or any guidance. Please Help.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

That's a little complicated, but possible - what you will have to do is create a graphics context on the label, use Graphics.MeasureString[^] to see how big it is going to be, and adjust the font size appropriately. Then repeat the measurements and see if you go it right!

Don't forget to Dispose unwanted Font and Graphics objects when you are finished with them.
   
Comments
Nipuna S Perera 5-Aug-14 9:16am
   
Thanks OriginalGriff.
I'm new to the programming world and C#. So, Could you please explain me how to do this?
would be grate help for me.
OriginalGriff 5-Aug-14 9:39am
   
See the documentation (it includes an example) - if you can't cope with it yet, then this is probably a bit beyond you at this stage and you would probably be better off finding a "simpler" user interface solution.
We aren't here to give you the code for your own work! :laugh:
Nipuna S Perera 5-Aug-14 10:20am
   
From where can I find documentation? please help.
Nipuna S Perera 5-Aug-14 10:24am
   
Hi, Sorry for the disturbance. I found it in your answer.
Thanks very much OriginalGriff! thanks!
OriginalGriff 5-Aug-14 10:26am
   
I was just about to suggest you followed the link! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100