BCB The total height of the text measured in RichEdit

Source: Internet
Author: User

RICHEDIT Rich text controls can hold a variety of fonts, so what if we want to know how high the head of the text is?

For example, we want to judge whether the text content in RichEdit is beyond the scope of RichEdit, how to achieve it?

1, need to use Em_formatrange message http://msdn.microsoft.com/en-us/library/bb788020%28VS.85%29.aspx

2, the implementation of the code is as follows: (The following is the implementation of BCB, StackOverflow on the implementation of Delphi

Http://stackoverflow.com/questions/3244139/how-to-get-text-extent-of-richedit-in-delphi)

//---------------------------------------------------------------------------#include<vcl.h>#pragmaHdrstop#include"Unit1.h"//---------------------------------------------------------------------------#pragmaPackage (Smart_init)#pragmaResource "*.DFM"TForm1*Form1;//---------------------------------------------------------------------------__fastcall Tform1::tform1 (tcomponent*owner): Tform (owner) {}//---------------------------------------------------------------------------void__fastcall Tform1::button1click (TObject *Sender) {RichEdit1->text = richedit1->text.trimright (); intlogx,logy; HDC RICHDC= GetDC (richedit1->Handle); LOGX=GetDeviceCaps (RICHDC, logpixelsx); Logy=GetDeviceCaps (RICHDC, logpixelsy); FormatRange FormatRange= {0}; FORMATRANGE.HDC=Richdc; Formatrange.hdctarget=Richdc; Formatrange.rc.left=0; Formatrange.rc.top=0; Formatrange.rc.right= Richedit1->clientwidth *1440/LOGX; Formatrange.rc.bottom= screen->height*1440/logy; Formatrange.rcpage=formatrange.rc; Formatrange.chrg.cpMin=0; Formatrange.chrg.cpMax= -1; RichEdit1->perform (Em_formatrange,0,(Long) &FormatRange); intTotalheight = Formatrange.rc.bottom * Logy/1440; ShowMessage ("Total Text Height"+INTTOSTR (Formatrange.rc.bottom * logy/1440)); RichEdit1->perform (Em_formatrange,0, NULL);//Free the cache    if(Totalheight > (richedit1->clientheight+3) {showmessage ("text out of range! "); }

ReleaseDC (RICHEDIT1->HANDLE,RICHDC);}//---------------------------------------------------------------------------void__fastcall Tform1::button2click (TObject *Sender) {RichEdit1->font->size++;}//---------------------------------------------------------------------------void__fastcall Tform1::button3click (TObject *Sender) {RichEdit1->font->size--;}//---------------------------------------------------------------------------

BCB The total height of the text measured in RichEdit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.