procedure TForm1.FormCreate(Sender: TObject); begin Label3.Caption := '用户名: Admin' + #13 + '密码: 123'; end; procedure TForm1.UserTxtKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then PSWTxt.SetFocus; end; procedure TForm1.PSWTxtKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then begin OKBtn.SetFocus; Exit; end; if ( Key < 48 )or ( Key > 57 ) then Key := 0; end; procedure TForm1.OKBtnClick(Sender: TObject); begin if ( UserTxt.Text = 'Admin' ) and ( PSWTxt.Text = '123' ) then Label3.Caption := 'login successfully' else begin Label3.Caption := 'error!' + #13 + 'please enter again.'; end; end; procedure TForm1.CancelBtnClick(Sender: TObject); begin UserTxt.Text := ''; PSWTxt.Clear; UserTxt.SetFocus; Label3.Caption := '用户名: Admin' + #13 + '密码: 123'; end; //转自《Delphi7程序设计与开发技术大全》