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 fromWelcome 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