字体设置器(TSpinEdit、TListBox使用)

DFM:

object FontSelectorfrm: TFontSelectorfrm
  Left = 568
  Top = 409
  Width = 205
  Height = 234
  Caption = #23383#20307#35774#32622#22120
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object lblFont: TLabel
    Left = 127
    Top = 8
    Width = 57
    Height = 25
    AutoSize = False
    Caption = #23383#20307#65306
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
  end
  object lblFontLarge: TLabel
    Left = 125
    Top = 144
    Width = 59
    Height = 20
    AutoSize = False
    Caption = #22823#23567#65306
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
  end
  object lstFont: TListBox
    Left = 125
    Top = 40
    Width = 62
    Height = 97
    ImeName = #20013#25991' ('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
    ItemHeight = 13
    TabOrder = 0
    OnClick = lstFontClick
  end
  object mmoText: TMemo
    Left = 8
    Top = 8
    Width = 105
    Height = 185
    ImeName = #20013#25991' ('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
    Lines.Strings = (
      'mmoText')
    TabOrder = 1
  end
  object seFontLarge: TSpinEdit
    Left = 125
    Top = 168
    Width = 65
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 2
    Value = 0
    OnChange = seFontLargeChange
  end
end

PAS:

unit frmFontSelector;

interface

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

type
  TFontSelectorfrm = class(TForm)
    lstFont: TListBox;
    mmoText: TMemo;
    lblFont: TLabel;
    lblFontLarge: TLabel;
    seFontLarge: TSpinEdit;
    procedure FormCreate(Sender: TObject);
    procedure lstFontClick(Sender: TObject);
    procedure seFontLargeChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FontSelectorfrm: TFontSelectorfrm;

implementation

{$R *.dfm}

procedure TFontSelectorfrm.FormCreate(Sender: TObject);
begin
  //Memo内容设置
  mmoText.Lines.Clear;
  mmoText.Lines.Append('测试内容');
  mmoText.Lines.Append('Test Content');
  //字体样式设置
  lstFont.Items.Clear;
  lstFont.Items.Append('隶书');
  lstFont.Items.Append('宋体');
  lstFont.Items.Append('黑体');
  lstFont.Items.Append('Arial');
  lstFont.Items.Append('Batang');
  lstFont.Items.Append('Broadway');
  //字体大小设置
  seFontLarge.MinValue := 5;
  seFontLarge.MaxValue := 30;
  seFontLarge.Increment := 1;
  seFontLarge.Value := 5;
end;

procedure TFontSelectorfrm.lstFontClick(Sender: TObject);
begin
  //设置字体
  mmoText.Font.Name := lstFont.Items.Strings[lstFont.itemIndex];
end;

procedure TFontSelectorfrm.seFontLargeChange(Sender: TObject);
var
  i: Integer;
  sFontLarge: string;
begin
  //获取当前字体大小值
  sFontLarge := seFontLarge.Text;
  //如果为空,则退出字体大小设置
  if sFontLarge = '' then
  begin
    Exit;
  end
  else
  begin
    //如果字体大小值中包括非法字符,则弹出提示信息并退出
    for i := 1 to Length(sFontLarge) do
    begin
      if sFontLarge[i] in ['+', '-', '.'] then
      begin
        ShowMessage('字体大小只能为整数值');
        seFontLarge.SelectAll;
        Exit;
      end;
    end;
    //设置字体大小
    mmoText.Font.Size := seFontLarge.Value;
  end;
end;

end.
截图:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值