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); }