我想在程序运行期间修改RichEdit里字体的颜色,谁能帮我举个例子!(20分)

  • 主题发起人 主题发起人 sh0
  • 开始时间 开始时间
richedit1.Font.Color := clred;
 
这个程序可以人吧!

unit UnRTF;

interface

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

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
ComboBox1: TComboBox;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
ColorDialog: TColorDialog;
Edit2: TEdit;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items:=Screen.Fonts;
ComboBox1.Text:='宋体';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if ColorDialog.Execute then
begin
Edit2.Color:=ColorDialog.Color;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
n:Integer;
begin
n:=Length(Edit2.text);
RichEdit1.Lines.Add(Edit2.Text);
RichEdit1.SelLength:=-n-2;
RichEdit1.SelAttributes.Name:=ComboBox1.Text;
RichEdit1.SelAttributes.Color:=Edit2.Color;
RichEdit1.SelAttributes.Size:=StrToInt(Edit1.text);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
RichEdit1.SelAttributes.Name:=ComboBox1.Text;
RichEdit1.SelAttributes.Color:=Edit2.Color;
RichEdit1.SelAttributes.Size:=StrToInt(Edit1.text);
RichEdit1.Lines.Add(Edit2.Text);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
RichEdit1.Lines.Add(Edit2.Text);
end;

end.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部