jdelozier
asked on
Total number of lines in RichTextBox
How can I determine the total number of lines in a richTextBox before the verticle scrollbar appears based on Font and Font Size/attributes?
Also, total number of lines before the horizontal scrollbar appears?
I prefer Managed C++ .net code but C# is fine too.
Also, total number of lines before the horizontal scrollbar appears?
I prefer Managed C++ .net code but C# is fine too.
Also you can refer to this link
http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.getlinefromcharindex(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.getlinefromcharindex(VS.80).aspx
ASKER
I've looked at the first link above before and the second I've seen also. I'll look more into these and see if I can find what I need. By both of your comments, if I can get the line numbers I can tell what line the textbox ends on.
ASKER
Found a way to do it using Font Measurement.
// Create dummy string for measurement
String^ text = "TEST STRING";
System::Drawing::Font^ textFont = tbReader->Font;
//Specify a fixed width, but let the height be "unlimited"
SizeF^ layoutSize = gcnew SizeF((float)tbReader->Wid th,
(float)5000.0F);
Graphics^ g = Graphics::FromHwnd(tbReade r->Handle) ;
SizeF^ stringSize = g->MeasureString(text, textFont, (SizeF)layoutSize);
// Divide RTB height by font height to determine how many it can hold.
int numLines = tbReader->Height / stringSize->Height;
// Return the number
return numLines;
// Create dummy string for measurement
String^ text = "TEST STRING";
System::Drawing::Font^ textFont = tbReader->Font;
//Specify a fixed width, but let the height be "unlimited"
SizeF^ layoutSize = gcnew SizeF((float)tbReader->Wid
(float)5000.0F);
Graphics^ g = Graphics::FromHwnd(tbReade
SizeF^ stringSize = g->MeasureString(text, textFont, (SizeF)layoutSize);
// Divide RTB height by font height to determine how many it can hold.
int numLines = tbReader->Height / stringSize->Height;
// Return the number
return numLines;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.codeproject.com/cs/miscctrl/numberedtextbox.asp