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

  • Thread starter Thread starter Hector Y. Martinez
  • Start date 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.
 
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
 
Back
Top