1. 登录界面的效果图
1.png
2.png
3.png
4.png
2. 登录界面实现的功能描述
实现不同的身份登陆
3. 登录界面各控件的参数设置
控件A
属性 |
值 |
TEXT |
用户登录 |
MaximizeBox |
False |
MinimizeBox |
False |
StartPosition |
CenterScreen |
控件label1
控件label2
控件label3
控件Linklabel1
控件comboBox1
属性 |
值 |
DropDownStyle |
DropDownList |
SelectedIndexChanged |
comboBox1_SelectedIndexChanged |
控件textBox1
属性 |
值 |
MaxLength |
9 |
Click |
textBox1_Click |
KeyPress |
textBox1_KeyPress |
TextChanged |
textBox1_TextChanged |
控件textBox2
属性 |
值 |
Click |
textBox1_Click |
KeyPress |
textBox2_KeyPress |
Enter |
text Box1_Enter |
MaxLength |
6 |
Passwordchar |
* |
控件button1
属性 |
值 |
Text |
登陆 |
UseVisualStyleBackColor |
False |
Click |
button1_Click |
控件button2
属性 |
值 |
Text |
退出 |
UseVisualStyleBackColor |
False |
Click |
button2_Click |
4. 重要方法描述
在Form窗口下,右击属性,在FormBorderStyle中选择FixdeSingle;将MaximizeBox和MinimizeBox设置为False,登录窗口就固定化了。
默认收银员
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.SelectedIndex = 0;
}
5.代码
private void button1_Click(object sender, EventArgs e)
{
if (this.comboBox1.SelectedItem.ToString() == "收银员")
{
if (this.textBox1.Text == "147258369" && this.textBox2.Text == "123456")
{
MessageBox.Show("收银员登录成功");
}
else
{
MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (this.comboBox1.SelectedItem.ToString() == "库管员")
{
if (this.textBox1.Text == "admin" && this.textBox2.Text == "admin")
{
MessageBox.Show("库管员登录成功");
}
else
{
MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
textBox2.Focus();
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
this.userLogin();
}
}
网友评论