歡迎光臨 Code²
Code Square, CodeSqaure, Pascal, Javascript
就如一般的Delphi程序,我們要做的第一件事就是設計使用者界面。Fontlist的功能並不复雜,所以使用界面很簡單,我們只需要五個TButton和一個TDrawGrid,字型的樣本將顯示在TDrawGrid上。使用TDrawGrid並沒有特別的原因,改用TListBox可以。
界面的截圖和dfm文件如下:
fontu.dfm顯示代碼
object Form1: TForm1
Left = 200
Top = 150
Width = 600
Height = 500
Caption = 'Fontlist'
Color = clBtnFace
Constraints.MinHeight = 400
Constraints.MinWidth = 500
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
Scaled = False
PixelsPerInch = 96
TextHeight = 13
object Grid: TDrawGrid
Left = 8
Top = 50
Width = 576
Height = 412
ColCount = 1
FixedCols = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goThumbTracking]
FixedRows = 0
ScrollBars = ssVertical
TabOrder = 0
end
object btnSystem: TButton
Left = 8
Top = 8
Width = 84
Height = 25
Caption = 'System fonts'
Enabled = False
TabOrder = 1
end
object btnFolder: TButton
Left = 108
Top = 8
Width = 84
Height = 25
Caption = 'Font from folder'
TabOrder = 2
end
object btnSelectFolder: TButton
Left = 208
Top = 8
Width = 84
Height = 25
Caption = 'Select folder'
Enabled = False
TabOrder = 3
end
object btnSaveBmp: TButton
Left = 308
Top = 8
Width = 84
Height = 25
Caption = 'Save as bmp'
TabOrder = 4
end
object btnClose: TButton
Left = 408
Top = 8
Width = 84
Height = 25
Caption = 'Close'
TabOrder = 5
OnClick = btnCloseClick
end
end
這時我們仍然未有多少代碼,只是簡單地加上了退出的功能:procedure btnCloseClick(Sender: TObject);。
fontu.pas隱藏代碼
unit Fontu;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
btnSystem: TButton;
btnFolder: TButton;
btnSelectFolder: TButton;
btnSaveBmp: TButton;
btnClose: TButton;
Grid: TDrawGrid;
procedure btnCloseClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btnCloseClick(Sender: TObject);
begin
Close;
end;
end.
FontList.dpr由Delphi自動產生,沒有任何變動。
FontList.dpr隱藏代碼
program FontList;
uses
Forms,
fontu in 'fontu.pas' ;
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
沒有留言:
發佈留言