TrichEdit可以同时显示不同的字体和颜色吗?

ahuige 2004-12-10 03:50:35
TrichEdit可以同时显示不同的字体和颜色吗?我知道RTF文件是可以,但是TRichEdit可以吗?
如何设置才对?
...全文
300 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
nhconch 2004-12-24
  • 打赏
  • 举报
回复
NND
xjwy 2004-12-21
  • 打赏
  • 举报
回复
jackie168(花好月圓) 做的对,第一个是在胡说八道
jackie168 2004-12-21
  • 打赏
  • 举报
回复
procedure TForm1.Button4Click(Sender: TObject);
begin
richedit1.SelStart:=sendmessage(richedit1.Handle,em_lineindex,0,0);
richedit1.SelLength:=length(richedit1.Lines[0]);
richedit1.SelAttributes.Color:=clred; //颜色
richedit1.SelAttributes.Size:=23; //字号
end;
ahuige 2004-12-21
  • 打赏
  • 举报
回复
有人做过这种多色显示的RichEdit的处理吗?
ahuige 2004-12-21
  • 打赏
  • 举报
回复
多谢,搞定,看来还是得API熟的windows开发高人来搞啊
hellolongbin 2004-12-21
  • 打赏
  • 举报
回复
可以,最简单的方法是你在word里写好后保存成rtf格式然后
RichEdit1.Lines.LoadFromFile('E:/hello.rtf');
自己看看吧
lemon_wei 2004-12-21
  • 打赏
  • 举报
回复
学习,呆会来试试
ahuige 2004-12-10
  • 打赏
  • 举报
回复
运行时找不到TCharacterFormat类型。
要use哪一个unit呢?帮助也查不到啊。是自定义的吗?
nhconch 2004-12-10
  • 打赏
  • 举报
回复

procedure TForm1.RE_SetCharFormat(RichEdit: TRichEdit;
CharacterFormat: TCharacterFormat);
var
// The CHARFORMAT structure contains information about
// character formatting in a rich edit control.
Format: TCharFormat;
begin
FillChar(Format, SizeOf(Format), 0);
with Format do
begin
cbSize := SizeOf(Format);
dwMask := CFM_OFFSET or CFM_SIZE or CFM_COLOR;
// 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.
case CharacterFormat of
CFM_Superscript:
begin
yOffset := 60;
yHeight := 200;
crTextColor := clGreen;
end;
CFM_Subscript:
begin
yOffset := -60;
yHeight := 200;
crTextColor := clBlue;
end;
CFM_Normal:
begin
yOffset := 0;
crTextColor := clBlack;
end;
end;
end;
// 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));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Superscript);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Subscript);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
RE_SetCharFormat(RichEdit1, CFM_Normal);
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧