How to get text width and hieght in a richtext box

P

Pubs

Hi all,

I have application being written in C# where I have to calculate the
text pixel height and width of the line being typed in rich text box.
I need to get the pixel height of the character next to cursor and the
total length of the row where the cursor is. Rich text box might have
different fonts with different styles I need to get the length in
pixels.
Can some one let me know an easy method ?

Pubdu
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi all,

  I have application being written in C# where I have to calculate the
text pixel height and width of the line being typed in rich text box.
I need to get the pixel height of the character next to cursor and the
total length of the row where the cursor is. Rich text box might have
different fonts with different styles I need to get the length in
pixels.
Can some one let me know an easy method ?

Pubdu

Hi,
I do not know how to get it from inside the RichTextBox, but you can
use Graphics.MeasureString , all you need to know is the string and
the Font to use
 
P

Pubs

Hi,
I do not know how to get it from inside the RichTextBox, but you can
use Graphics.MeasureString , all you need to know is the string and
the Font to use

thank you for the replyt
 
P

Pavel Minaev

Is there a way to scroll the text of the richtext Box to a specific Line
number and makes the cursor points to that Line Number?

You should look at the following members of TextBoxBase (from which
RichTextBox derives):

GetFirstCharIndexFromLine
Select
ScrollToCaret

To position the caret in the textbox, you need to "select" zero characters
starting at the position you want to put the caret at.
 

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