text length in pixels

V

Vishal Gupta

Hi,

I am trying to resolve the following scenario:
We have a text box of fixed width that by default should display only 1 line
of text without a scrollbar indicator.
If there are multiple lines of text then we need to to indicate that by
displaying a button alongside the textbox that the user can click on to
expand the height of the text box. The height would be, say, 4 lines of
text. If there are more than 4 lines of text then we need to display a
vertical scrollbar.
To be able to achieve this, it seems, we need to be able to compare the
length of the text with that of the textbox. If we can somehow get the
length in pixels that would solve part of the problem?

Any ideas would be greatly appreciated...

Thanks, Vishal
 
S

Scott M.

Instead of trying to accomplish this by pixels (the hard way), try this:

A textbox that does not have any styling applied to it will use a font where
different characters are different widths (capital W is wider than lower
case l). So, pick a number of characters that you consider to be one full
line of text. You can programmatically check the number of characters in a
textbox and when you reach your one line limit, you can change the rows
property of the textbox to 4. The vertical scroll bar is built in, so you
don't have to worry about enabling it when needed.
 
R

Rick Lemons

Check out the .NET Framework Class Library for:

Graphics.MeasureString Method (String, Font)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top