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的字体、颜色会跟着改变,这应该算是取得了您要的吧,至于知道了颜色、字体,大小,接下来要干什么,就看您的了。:-)勿勿写了几行,未运行测试,应该没问题吧。
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;
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.