//---------------------------------------------------------------------------
typedef enum { CFM_Superscript, // 上标 CFM_Subscript, // 下标 CFM_Normal // 普通文本 }TCharacterFormat;
void MySetCharFormat(TRichEdit *RichEdit, TCharacterFormat CharacterFormat) { // ccrun(老妖)根据Delphi超级猛料中的资料修改而成
// 欢迎光临 C++ Builder 研究 http://www.ccrun.com TCharFormat Format; Format.cbSize = sizeof(Format); Format.dwMask = CFM_OFFSET; // Character offset, in twips, from the baseline. // If the value of this member 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)); } //--------------------------------------------------------------------------- // 先选中Richedit中的部分文本,然后点击此按钮,选中文本将变成上标 void __fastcall TForm1::Button1Click(TObject *Sender) { // 上标 MySetCharFormat(RichEdit1, CFM_Superscript); } //--------------------------------------------------------------------------- // 先选中Richedit中的部分文本,然后点击此按钮,选中文本将变成下标 void __fastcall TForm1::Button2Click(TObject *Sender) { // 下标 MySetCharFormat(RichEdit1, CFM_Subscript); } |