Click here to Skip to main content
15,878,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Can you tell how to determine numbers of lines which currently are visible in RichTextBox?"
Updated 29-Feb-12 2:36am
Syed Salman Raza Zaidi 29-Feb-12 8:15am    
Не могли бы вы подробнее рассказать или поделиться некоторыми из вас код??
[no name] 29-Feb-12 8:15am    
This is an English language forum. If you need help, please use an online transaltor to translate your question.

Not nice, but...
Try this:
int top = myRichTextBox.GetCharIndexFromPosition(new Point(1, 1));
int bottom = myRichTextBox.GetCharIndexFromPosition(new Point(1, myRichTextBox.Height - 1));

int topLine = myRichTextBox.GetLineFromCharIndex(top);
int bottomLine = myRichTextBox.GetLineFromCharIndex(bottom);

int linesDisplayed = bottomLine - topLine;
Console.WriteLine("{0}:{1} = {2}", topLine, bottomLine, linesDisplayed);
Share this answer
Andy1828 29-Feb-12 9:09am    
It works! I believe it is the best decision. Thank you!
OriginalGriff 29-Feb-12 9:18am    
You're welcome!
ProEnggSoft 29-Feb-12 11:03am    
Good answer. My 5.
and how about this one:
int charCount;
int lineCount;
    new SizeF(richTextBox1.Width, richTextBox1.Height),
    new StringFormat(StringFormatFlags.FitBlackBox), 
    out charCount, 
    out lineCount);

the lineCount-1 value seems to be the correct visible lines count
Share this answer
Andy1828 29-Feb-12 11:09am    
Thanks, but really, I needed the screen string to work with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900