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

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

Post by SGVjdG9yIF » Sat, 08 Aug 2009 07:12:08



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.

--
"The best way to predict the future, is to invent it"
 
 
 

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

Post by RmFtaWx5IF » Sun, 09 Aug 2009 02:26:01


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