<b>如安在RichEdit中实现上标下标</b>[VC/C++编程]
本文“<b>如安在RichEdit中实现上标下标</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
近来有好多朋友在csdn问如安在RichEdit中实现上标下标,查了好多资料都没找到.本日无意间在Delphi区闲逛,看到一份实现上下标的文章,于是整理成CB语言的贴出来.
以下代码已测试通过.在Form中安排一个RichEdit,两个Button,完好代码以下:
//--------------------------------------------------------------------------- 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);
}
假如您有其他的设法和倡议,欢送来信探究:info@ccrun.com
以上是“<b>如安在RichEdit中实现上标下标</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |