Delphi5实现“书籍介绍”——编辑框组件实例

效果图

在这里插入图片描述

参考

3.5 编辑型组件

组件

在这里插入图片描述
使用快捷键: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;

完整代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值