Closed Thread
Results 1 to 4 of 4

Thread: Number of Lines on a RichText Box

  1. #1
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30

    Number of Lines on a RichText Box

    How can I find the number of lines on a richtextbox? I'd like to know how many lines I could paste.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    RobSoftware is offline Programmer
    Join Date
    Nov 2005
    Posts
    143
    Rep Power
    0
    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;
    		 }

  4. #3
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    Works perfect! Thank you!

  5. #4
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    Nice code! how long have you been using .NET Rob?

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I erase lines in C#?
    By qu20 in forum C# Programming
    Replies: 4
    Last Post: 05-10-2010, 03:21 AM
  2. 88 lines about 44 fan girls
    By zeroradius in forum The Lounge
    Replies: 0
    Last Post: 05-08-2010, 02:15 AM
  3. Ten Lines or Less!
    By ZekeDragon in forum Games
    Replies: 26
    Last Post: 08-30-2009, 05:06 PM
  4. Intercept of two lines
    By ejbennett in forum C and C++
    Replies: 3
    Last Post: 01-18-2009, 05:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts