效果图
参考
组件
使用快捷键:alt+字符
加粗
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
Memo1.Font.Style:=Memo1.Font.Style+[fsBold] //文本加粗
else
Memo1.Font.Style:=Memo1.Font.Style-[fsBold]
end;
倾斜
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then
Memo1.Font.Style:=Memo1.Font.Style+[fsItalic] //文本倾斜
else
Memo1.Font.Style:=Memo1.Font.Style-[fsItalic]
end;
字体样式
将 RichEdit1 控件当前选中文本的字体属性 (SelAttributes) 复制到 font 对象中。这确保了在修改字体属性时,保留了选中文本的原有字体设置。
{将复文本编辑框中选定文本的字体设置成指定字体式样}
procedure TForm1.RadioGroup1Click(Sender: TObject);
var
font:TFont;
begin
font:=TFont.Create;
font.Assign(RichEdit1.SelAttributes);
if RichEdit1.SelLength>0 then
begin
case RadioGroup1.ItemIndex of
0:begin //标题
font.Style:=font.Style+[fsBold];
font.Size:=20;
end;
1:begin //正文
font.Size:=12;
end;
2:begin //提示
font.Size:=12;
font.Style:=font.Style+[fsItalic]+[fsBold];
end;
3:begin //注释
font.Size:=10;
font.Style:=font.Style+[fsUnderline];
end;
end;
RichEdit1.SelAttributes.Assign(font);
end;
end;
每当重新进入RichEdit1,复原RadioGroup1状态
procedure TForm1.RichEdit1Enter(Sender: TObject);
begin
RadioGroup1.ItemIndex:=-1;
end;
完整代码
在这。