How can I find the number of lines on a richtextbox? I'd like to know how many lines I could paste.
Code://////////////////////////////////////////////////////////// //** 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; }
Works perfect! Thank you!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks