Click here to Skip to main content
15,307,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Does anyone know how to accurately get the text content height from a rich text box?

I have tried the following code:

private void CalculateContentHeight()
           Graphics g = this.CreateGraphics();
           SizeF overallSize = default(SizeF);
           Point pt = default(Point);this.Font.Style);
           SendMessageW(this.Handle, EM_GETSCROLLPOS, 0, ref pt);
           overallSize =  TextRenderer.MeasureText(g, Text, Font);

           // send max value and value to any listenting controls so they can scroll syncronously
           if (this.Scroll != null)
               this.Scroll(this, new ScrollEventArgs(pt.Y, Convert.ToInt32(overallSize.Height - this.Height)));

However it is still out when i copy and paste different formats into the box.

Is there any way of it accurately pulling out this information?

Thanks in advance


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900