How can I find the number of lines on a richtextbox? I'd like to know how many lines I could paste.
Number of Lines on a RichText Box
Started by Lop, May 09 2006 04:31 AM
3 replies to this topic
#1
Posted 09 May 2006 - 04:31 AM
|
|
|
#2
Posted 10 May 2006 - 01:14 AM
////////////////////////////////////////////////////////////
//** This returns the total number of lines the rich
//** text box can hold
////////////////////////////////////////////////////////////
private: int GetTotalNumberLines() {
String^ text = "TEST STRING";
System::Drawing::Font^ textFont = richTextBox1->Font;
//Specify a fixed width, but let the height be "unlimited"
SizeF^ layoutSize = gcnew SizeF((float)richTextBox1->Width,
(float)5000.0F);
Graphics^ g = Graphics::FromHwnd(richTextBox1->Handle);
SizeF^ stringSize = g->MeasureString(text, textFont, (SizeF)layoutSize);
// Divide RTB height by font height to determine how many it can hold.
int numLines = richTextBox1->Height / stringSize->Height;
// Return the number
return numLines;
}
#3
Posted 15 June 2006 - 03:26 PM
Works perfect! Thank you!
#4
Posted 16 June 2006 - 02:19 PM
Nice code! how long have you been using .NET Rob?


Sign In
Create Account


Back to top









