A question on RighTextBox ...

P

Polaris

Hi:

Is there a way to tell exactly how many chars a RichTextBox can display (no
scroll bars)? The Font used may not be fixed width font.

Thanks in advance!
Polaris
 
K

Kevin Spencer

Not exactly. Because you can change the font in the box, there is really not
an exact number of characters. You can use the Graphics.MeasureString
method, which takes a font and a string, to measure the size of the
rectangle that will be occupied by a string of a given font. However, since
the font can be changed at any point in a RichTextBox, you would have to
continually re-measure the text in separate chunks (one chunk per font
change) to find out the rectangle size occupied by any current amount of
text in the RichTextBox, and of course, once the font changed, the remaining
number of characters would change as well. In addition, you would have to
factor in the ability or inability of the user to change the font via
selection and other run-time techniques that may or may not be available,
depending upon how you're using it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Abnormality is anything but average.
 

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

Top