Delphi制作一个密码小程序
大家来看看我是怎么用Delphi制作一个密码小程序的吧!
程序密码:123456
因为:
Password:String = '123456';If (Edit1.Text = Password) then
先上代码:
1 unit key; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Label1: TLabel; 12 Edit1: TEdit; 13 Button1: TButton; 14 procedure FormCreate(Sender: TObject); 15 procedure Button1Click(Sender: TObject); 16 private 17 { Private declarations } 18 public 19 { Public declarations } 20 end; 21 22 var 23 Form1: TForm1; 24 25 implementation 26 const 27 Password:String = '123456'; 28 29 var 30 n:Integer = 3; 31 {$R *.dfm} 32 33 procedure TForm1.FormCreate(Sender: TObject); 34 begin 35 SetWindowLong(Edit1.Handle,GWL_STYLE,GetWindowLong(Edit1.Handle,GWL_STYLE) Or ES_CENTER); 36 Edit1.Invalidate; 37 end; 38 39 procedure TForm1.Button1Click(Sender: TObject); 40 begin 41 If (Edit1.Text = Password) then 42 MessageBox(handle,'恭喜您,密码正确!','正确提示',MB_OK Or MB_ICONWARNING) 43 Else 44 begin 45 n:=n-1; 46 If(n < 1) then 47 begin 48 MessageBox(handle,'您的密码错误次数已达上限,将自动关闭程序','错误提示',MB_OK Or MB_ICONSTOP); 49 Close; 50 end 51 ELSE 52 begin 53 Label1.Caption:='密码错误,请重新输入,您还有' + IntToStr(n)+'次机会!'; 54 Edit1.Text:='' ; 55 end; 56 end; 57 end; 58 59 end.
大家来看看主程序效果!
1、输入密码前

大家注意看:他的输入指针是居中的
2、输入密码

注意看:它隐藏了输入字符
3、密码输入正确

4、输入错误1次

5、输入错误2次

大家注意看:输入错误了,输入框是被清除的
6、输入错误3次

7、点击6图的确定后

所有东西都关掉了
浙公网安备 33010602011771号