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.
截图: