How to implement superscript subscript in RichEdit

Source: Internet
Author: User

Recently a lot of friends in Csdn asked how in the RichEdit to achieve superscript subscript, check a lot of data have not found. Today inadvertently wandering in the Delphi area, see a implementation of the superscript, so the article into a CB language posted out.

The following code has been tested for adoption. In the form, place a RichEdit, two button, complete with the following code:

---------------------------------------------------------------------------typedef enum
{
Cfm_superscript,//superscript
Cfm_subscript,//subscript
Cfm_normal//Plain text
}tcharacterformat;
void Mysetcharformat (Trichedit *richedit, Tcharacterformat Characterformat)
{
Ccrun (old demon) according to Delphi Super fierce material in the data modified from

Welcome to C + + Builder research http://www.ccrun.com
Tcharformat Format;
format.cbsize = sizeof (Format);
Format.dwmask = Cfm_offset;
Character offset, in twips, from the baseline.
If The value is positive,
The character is a superscript;
If it is negative, the character is a subscript.
Switch (Characterformat)
{
Case Cfm_superscript:
Format.yoffset = 60;
Break
Case Cfm_subscript:
Format.yoffset =-60;
Break
Case Cfm_normal:
Format.yoffset = 0;
Break
Default
Break
}
The Em_setcharformat message sets character formatting in a rich edit control.
Scf_selection:applies the formatting to the current SELECTION
Richedit->perform (Em_setcharformat, Scf_selection, Longint (&format));
}
//---------------------------------------------------------------------------
Select some of the text in RichEdit, and then click this button to select the text to become superscript
void __fastcall Tform1::button1click (tobject *sender)
{
Superscript
Mysetcharformat (RichEdit1, cfm_superscript);
}
//---------------------------------------------------------------------------
Select some of the text in RichEdit, and then click this button, and the selected text will become subscript
void __fastcall Tform1::button2click (tobject *sender)
{
Subscript
Mysetcharformat (RichEdit1, cfm_subscript);
}

If you have other ideas and suggestions, please feel free to discuss the letter: info@ccrun.com

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.