📄 frmlogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Example_1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Label lblDebitCardNumber;
private System.Windows.Forms.TextBox txtDebitCardNumber;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Button btnLogin;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmLogin()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblPassword = new System.Windows.Forms.Label();
this.lblDebitCardNumber = new System.Windows.Forms.Label();
this.txtDebitCardNumber = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnLogin = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(32, 47);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(72, 23);
this.lblPassword.TabIndex = 0;
this.lblPassword.Text = "密码:";
//
// lblDebitCardNumber
//
this.lblDebitCardNumber.Location = new System.Drawing.Point(32, 15);
this.lblDebitCardNumber.Name = "lblDebitCardNumber";
this.lblDebitCardNumber.Size = new System.Drawing.Size(112, 23);
this.lblDebitCardNumber.TabIndex = 0;
this.lblDebitCardNumber.Text = "借记卡号:";
//
// txtDebitCardNumber
//
this.txtDebitCardNumber.Location = new System.Drawing.Point(152, 16);
this.txtDebitCardNumber.MaxLength = 10;
this.txtDebitCardNumber.Name = "txtDebitCardNumber";
this.txtDebitCardNumber.Size = new System.Drawing.Size(109, 21);
this.txtDebitCardNumber.TabIndex = 1;
this.txtDebitCardNumber.Text = "";
this.txtDebitCardNumber.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtDebitCardNumber_KeyPress);
this.txtDebitCardNumber.Leave += new System.EventHandler(this.txtDebitCardNumber_Leave);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(152, 48);
this.txtPassword.MaxLength = 6;
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(109, 21);
this.txtPassword.TabIndex = 2;
this.txtPassword.Text = "";
this.txtPassword.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPassword_KeyPress);
this.txtPassword.Leave += new System.EventHandler(this.txtPassword_Leave);
//
// btnLogin
//
this.btnLogin.Enabled = false;
this.btnLogin.Location = new System.Drawing.Point(184, 80);
this.btnLogin.Name = "btnLogin";
this.btnLogin.TabIndex = 3;
this.btnLogin.Text = "登录(&L)";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(288, 117);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtDebitCardNumber);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.lblDebitCardNumber);
this.Controls.Add(this.btnLogin);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "frmLogin";
this.Text = " ATM 登录屏幕";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmLogin());
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
frmAccountDetails objAccountDetails = new frmAccountDetails();
this.Hide();
objAccountDetails.Show();
}
private void txtDebitCardNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//仅接受 0-9 和退格键
e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
if(e.KeyChar == (char)8)
e.Handled=false;
}
private void txtDebitCardNumber_Leave(object sender, System.EventArgs e)
{
int count = this.txtDebitCardNumber.Text.Length;
if(count < 10)
{
MessageBox.Show("请输入 10 位数字的借记卡号","借记卡");
this.txtDebitCardNumber.Focus();
}
}
private void txtPassword_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//仅接受 0-9 和退格键
e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
if(e.KeyChar == (char)8)
e.Handled=false;
}
private void txtPassword_Leave(object sender, System.EventArgs e)
{
int count = this.txtPassword.Text.Length;
if(count < 6)
{
MessageBox.Show("密码的长度应该为 6 个字符","密码");
this.txtPassword.Focus();
}
else
{
this.btnLogin.Enabled=true;
this.btnLogin.Focus();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -