now can i know the line size in a richTextBox control ??

  • Thread starter Hector Y. Martinez
  • Start date
H

Hector Y. Martinez

I have this situation, I'm using another vScrollBar to scroll the text in a
richtextbox, not the one who comes with the control, (for some reasons), then
I want to know when I should put visible this scrollbar... then, to do that I
know how many lines of text i got, by I don't know the exactly size of one
line, It depends of the font size, and the space between lines, this space
look like it also depends of the font size. How can i know in any moment,
with any font, the exactly height of the text, plus the space between line,
in order to get total height of the text ???

Thanx in advance... Hector.
 
F

Family Tree Mike

Hector Y. Martinez said:
I have this situation, I'm using another vScrollBar to scroll the text in a
richtextbox, not the one who comes with the control, (for some reasons), then
I want to know when I should put visible this scrollbar... then, to do that I
know how many lines of text i got, by I don't know the exactly size of one
line, It depends of the font size, and the space between lines, this space
look like it also depends of the font size. How can i know in any moment,
with any font, the exactly height of the text, plus the space between line,
in order to get total height of the text ???

Thanx in advance... Hector.

If you are subclassing RichTextBox, then you can create a function like this:

bool VScrollNeeded()
{
// measure the text drawn by the control
Graphics g = Graphics.FromHwnd(this.Handle);
SizeF s = g.MeasureString(this.Text, this.Font);

// compare the drawn height to the control height
return s.Height > this.Height;
}

Mike
 

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