Get RichEdit default line spacing in BCB

Source: Internet
Author: User

First of all, these functions support RichEdit2.0 above functions;

Secondly, the conventional method is unable to obtain the linespace;

    • You won't get it using Em_getparaformat, you'll find that the value of dylinespacing is always 0.
    • You first Em_setparaformat, specify Blinespacingrule = 4, and then use GetParaFormat to fetch dylinespacing is also 0

Maybe RichEdit's author has a way.

https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/f67f6416-eab3-4aee-bfcc-85b9f26fde39/ Rich-edit-control-line-height

Below is the blog of the RichEdit author

https://blogs.msdn.microsoft.com/murrays/2010/01/12/richedit-versions-1-0-through-3-0/#comment-12105

Here is my solution.

I found a pattern when using Em_setparaformat to change the spacing between lines. The height of the whole text area also changed.

The code is as follows

//---------------------------------------------------------------------------#include<vcl.h>#pragmaHdrstop#include"Unit1.h"//---------------------------------------------------------------------------#pragmaPackage (Smart_init)#pragmaResource "*.DFM"TForm1*Form1;Static intLinespace = -;//---------------------------------------------------------------------------__fastcall Tform1::tform1 (tcomponent*owner): Tform (owner) {}//---------------------------------------------------------------------------void__fastcall Tform1::button1click (TObject *Sender) {RichEdit1-SelectAll ();    PARAFORMAT2 Para; Para.cbsize=sizeof(Para); Para.dwmask=pfm_linespacing; Para.blinespacingrule=4; Para.dylinespacing=Linespace; SendMessage (RichEdit1->handle, Em_setparaformat,0, LPARAM (&Para));}//---------------------------------------------------------------------------

From this we get inspired, if we start at 1, the Linspace is 1, then gradually accumulate.

When the height of the text area and the default text height are the same, do you get the corresponding value of Linespace?

Question 1, how do I get the height of the text area? Look at one of my other blogs http://www.cnblogs.com/songr/p/5485187.html

Question 2, calculation, this super simple;

Here is the implementation code

//---------------------------------------------------------------------------#include<vcl.h>#pragmaHdrstop#include"Unit1.h"//---------------------------------------------------------------------------#pragmaPackage (Smart_init)#pragmaResource "*.DFM"TForm1*Form1;Static intLinespace = -;//---------------------------------------------------------------------------__fastcall Tform1::tform1 (tcomponent*owner): Tform (owner) {}//---------------------------------------------------------------------------void__fastcall Tform1::button1click (TObject *Sender) {RichEdit1-SelectAll ();    PARAFORMAT2 Para; Para.cbsize=sizeof(Para); Para.dwmask=pfm_linespacing; Para.blinespacingrule=4; Para.dylinespacing=Linespace; SendMessage (RichEdit1->handle, Em_setparaformat,0, LPARAM (&Para));}//---------------------------------------------------------------------------inttform1::gettextareaheight () {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; RichEdit1->perform (Em_formatrange,0, NULL); ReleaseDC (RichEdit1-HANDLE,RICHDC); returntotalheight;}void__fastcall Tform1::button2click (TObject *Sender) {//first set the RichEdit as the default single spacingRichedit1->SelectAll ();    PARAFORMAT2 Para; Para.cbsize=sizeof(Para); Para.dwmask=pfm_linespacing; Para.blinespacingrule=0; SendMessage (RichEdit1->handle, Em_setparaformat,0, LPARAM (&Para));//get the text area height by default    intDeftextareaheight =gettextareaheight (); inti =0;  Do    {//Keep changing line spacing until the text area is the same height as by defaulti++;        PARAFORMAT2 Para; Para.cbsize=sizeof(Para); Para.dwmask=pfm_linespacing; Para.blinespacingrule=4; Para.dylinespacing=i; SendMessage (RichEdit1->handle, Em_setparaformat,0, LPARAM (&Para)); }     while(Deftextareaheight! =gettextareaheight ()); ShowMessage (IntToStr (i));//---------------------------------------------------------------------------

Note that the text area is the same height when it accumulates to 278. That is, 278 is the baseline of the default line height.

With this baseline. I can use this 278 as, we calculate the base value of the row height. (For example, when you reduce row height, you cannot be less than this value.) )

Get RichEdit default line spacing in BCB

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.