Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Total number of lines in RichTextBox

Posted on 2006-03-29
6
Medium Priority
?
263 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:jdelozier
5 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16329062
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 16360850
0
 

Author Comment

by:jdelozier
ID: 16385280
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.  
0
 

Author Comment

by:jdelozier
ID: 16396688
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->Width,
                         (float)5000.0F);
                   Graphics^ g = Graphics::FromHwnd(tbReader->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;
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 16584959
PAQed with points refunded (125)

DarthMod
Community Support Moderator
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question