source: tags/1.3.1/Inp.pas

Last change on this file was 442, checked in by chronos, 2 years ago
  • Modified: Code cleanup.
File size: 2.8 KB
Line 
1{$INCLUDE Switches.inc}
2unit Inp;
3
4interface
5
6uses
7 ScreenTools, LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
8 DrawDlg, ButtonA, StdCtrls;
9
10type
11 TInputDlg = class(TDrawDlg)
12 OKBtn: TButtonA;
13 EInput: TEdit;
14 procedure OKBtnClick(Sender: TObject);
15 procedure FormPaint(Sender: TObject);
16 procedure FormCreate(Sender: TObject);
17 procedure EInputKeyPress(Sender: TObject; var Key: Char);
18 procedure FormShow(Sender: TObject);
19 procedure FormClose(Sender: TObject; var Action: TCloseAction);
20 public
21 procedure CenterToRect(Rect: TRect);
22 private
23 Center: boolean;
24 end;
25
26var
27 InputDlg: TInputDlg;
28
29
30implementation
31
32{$R *.lfm}
33
34procedure TInputDlg.FormCreate(Sender: TObject);
35begin
36 Canvas.Font.Assign(UniFont[ftNormal]);
37 Canvas.Brush.Style := bsClear;
38 TitleHeight := Height;
39 InitButtons;
40 Center := True;
41end;
42
43procedure TInputDlg.FormPaint(Sender: TObject);
44begin
45 PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6);
46 Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
47 Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
48 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
49 Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
50 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
51 EditFrame(Canvas, EInput.BoundsRect, MainTexture);
52 BtnFrame(Canvas, OKBtn.BoundsRect, MainTexture);
53 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, Caption)) div 2,
54 9, Caption);
55 { Corner(canvas,1,1,0,MainTexture);
56 Corner(canvas,ClientWidth-9,1,1,MainTexture);
57 Corner(canvas,1,ClientHeight-9,2,MainTexture);
58 Corner(canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); }
59end;
60
61procedure TInputDlg.OKBtnClick(Sender: TObject);
62begin
63 if EInput.Text = '' then
64 ModalResult := mrCancel
65 else
66 ModalResult := mrOK;
67end;
68
69procedure TInputDlg.EInputKeyPress(Sender: TObject; var Key: Char);
70begin
71 if (Key = #13) and (EInput.Text <> '') then
72 begin
73 Key := #0;
74 ModalResult := mrOK;
75 end
76 else if Key = #27 then
77 begin
78 Key := #0;
79 ModalResult := mrCancel;
80 end;
81end;
82
83procedure TInputDlg.FormShow(Sender: TObject);
84begin
85 OKBtn.Caption := Phrases.Lookup('BTN_OK');
86 EInput.Font.Color := MainTexture.ColorMark;
87 EInput.SelStart := 0;
88 EInput.SelLength := Length(EInput.Text);
89 if Center then
90 CenterToRect(Rect(0, 0, Screen.Width, Screen.Height));
91end;
92
93procedure TInputDlg.FormClose(Sender: TObject; var Action: TCloseAction);
94begin
95 Center := True;
96end;
97
98procedure TInputDlg.CenterToRect(Rect: TRect);
99begin
100 Center := False;
101 Left := Rect.Left + (Rect.Right - Rect.Left - Width) div 2;
102 Top := Rect.Top + (Rect.Bottom - Rect.Top - Height) div 2;
103end;
104
105end.
Note: See TracBrowser for help on using the repository browser.