Jump to content

Number of Lines on a RichText Box

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
How can I find the number of lines on a richtextbox? I'd like to know how many lines I could paste.

#2
RobSoftware

RobSoftware

    Programmer

  • Members
  • PipPipPipPip
  • 143 posts

		 ////////////////////////////////////////////////////////////

		 //** 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
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Works perfect! Thank you!

#4
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
Nice code! how long have you been using .NET Rob?