如何读取RichEdit中文字和颜色、字体等数据?

coolqiang 2000-01-14 08:19:00
就是程序运行后,我要在RichEdit中进行简单的编辑(主要是不同颜色),编辑完后要将这些文字按颜色不同进行处理,那么怎样读出这些文字和这些文字是什么颜色的呢?
...全文
633 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeah 2000-01-19
  • 打赏
  • 举报
回复
在RichEdit的SelectionChange事件中可捕获到当前文本的属性。
例如,在窗体上放一个panel,Caption设为Test

function CurrentText:TTextAttributes;
begin
if Richedit.SelLength=0 then
Result:=Richedit.DefAttributes
else
Result:=RichEdit.SelAttributes;
end;

procedure TForm1.RicheditSelectionChange(Sender:TObject);
begin
With CurrentText do
begin
Panel1.Color:= Color;
Panel1.Font.name:=Name;
Panel1.Font.Size:=Size;
panel1.font.style:=....
....
end;
end;
在Richedit中写几行字,设置不同的颜色、字体,当您移动光标时,Panel1的字体、颜色会跟着改变,这应该算是取得了您要的吧,至于知道了颜色、字体,大小,接下来要干什么,就看您的了。:-)勿勿写了几行,未运行测试,应该没问题吧。
coolqiang 2000-01-16
  • 打赏
  • 举报
回复
能不能具体一些,最好提供一个简单的示例程序!谢谢!
Firing_Sky 2000-01-15
  • 打赏
  • 举报
回复
用SelAttributes.xxxxx等一套东东
yeah 2000-01-14
  • 打赏
  • 举报
回复
如果SelLength=0
richedit.DefAttributes.Color...Name...Size
否则使用
Richedit.SelAttributes.Color...Name...Size
Venne 2000-01-14
  • 打赏
  • 举报
回复
//***********************************
//试试这个,可以读取RICHEDIT中的属性,
//你可以通过设置SELSTART和SELLENGTH逐个
//处理你的东东.
//TEST.RTF是一个富文本格式,你可以试试
//在其中加入不同的颜色,LABEL的颜色跟着
//你文本的颜色改变.
//***********************************

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Label1: TLabel;
procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
NowColor:TColor;
begin
With RichEdit1 do begin
NowColor:=RichEdit1.SelAttributes.Color ;
end;

Label1.Font.Color :=nowColor;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Richedit1.Lines.LoadFromFile ('C:\test.rtf');
end;

end.
WHQ 2000-01-14
  • 打赏
  • 举报
回复
The EM_GETCHARFORMAT message determines the current character formatting in a rich edit control.

EM_GETCHARFORMAT
wParam = (WPARAM) (BOOL) fSelection;
lParam = (LPARAM) (CHARFORMAT FAR *) lpFmt;


Parameters

fSelection

Value specifying whether to get the default character formatting or the current selection's character formatting. If this parameter is zero, the default formatting is returned. Otherwise, the current selection's formatting is returned.

lpFmt

Pointer to a CHARFORMAT structure to fill in. If the selection formatting is being retrieved, the structure receives the attributes of the first character, and the dwMask member specifies which attributes are consistent throughout the entire selection.



Return Values

Returns the value of the dwMask member of the CHARFORMAT structure.

5,392

社区成员

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

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