954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

resize font to fit control

i have a richtextbox where the user inputs his/her name.. This needs to always be 60pixels wide, regardless of text..

ie: Johnathon

or Tim

need to be resized to best fit the control.

i've looked on the net, but only found VB solutions. Is there a way to achieve this?..


Thanks..

walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

As far as I know, the code in VB may be replaced with a similar code in C#. But, I doubt if playing with font size is a handy idea. Dunno about others, but I, personally, look cautious at web elements, who are living with their own life =) E.g. changing it's size or placement, so I need to wait till the "magic" would finish and then try continue to work.

It's just MHO .. and maybe in your case it's needed, but I decided to share my concerns :)

P.S. Here's what I've found in C#: C# Tutorial - Font Scaling

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

yes, i agree with you antenka. i've now changed it, so the user can scale the font to the desired size, then i just output the text using the current font size etc.. now i just have to figure out finding the textbox's current X,Y, then adding these values in a pdf which is using "mm" units.. :/ argh!.. stupid idiot proof program!

ps.. you wouldn't know which is better to use..

textbox.bounds.location.x? or
textbox.location.x?
or another method to get the current X Y of the textbox?..

they both work, but i get odd results when the user moves the textbox a few times..

anyways, thanks for the reply.. :)

walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

Hello,
as MSDN says,
Control.Bounds Property: Gets or sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control.
andControl.Location Property: Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.

If you're ok with a Location, you probably should use it. If you need something more than upper corner coords - use Bounds :)

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: