一. 登录界面的效果图
20181016-0.png
二. 登录界面实现的功能描述
具体要求:
1. 登录窗口出现在屏幕正中央,并且不能放大缩小
2. 默认角色为“收银员”,并且只允许选择“收银员”和“库管员”两种角色
3. 用户名最大长度不超过9个字符,密码需要显示为“*”号
4. 登录正确则提示成功;登录失败则提示错误,注意使用错误图标
5. 点击“退出”时退出应用程序
加分项:
1. 输入用户名后回车,光标跳转到密码输入框(涉及到 KeyPress 事件和 Tab 键顺序)
2. 输入密码后回车,则直接登录(涉及到 TextBox 的 KeyPress 事件)
3. 按 Tab 进入输入框时,自动全选(涉及到 TextBox 的 Enter事件)
三. 登录界面各控件的参数设置
1.Lable控件
属性 |
值 |
Text |
用户类型/用户名/密码 |
Font |
幼圆,14.25pt |
2.comebox控件
3.Textbox控件
属性 |
值 |
Font |
幼圆,14.25pt |
MaxLength |
6 |
PasswordChar |
* |
4.linkLable控件
属性 |
值 |
Font |
幼圆,14.25pt |
Text |
忘记密码 |
5.button控件
属性 |
值 |
Font |
幼圆,14.25pt |
Text |
登录/退出 |
6.pictureBox控件
属性 |
值 |
Font |
幼圆,14.25pt |
Backgroundlmage |
导入 |
BackgroundlmageLayout |
Stretch |
7.Form
属性 |
值 |
Font |
幼圆,9pt |
Text |
用户登录 |
FormBorderStyle |
FixedToolWindow |
四. 重要方法描述
1.窗口加载时,设置默认角色为“收银员”
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.SelectedIndex = 0;
}
2.点击“登录”按钮则登录系统
private void button1_Click(object sender, EventArgs e)
{
if (this.comeboBox1.SelectedItem.ToString() == "收银员")
{
if (this.textBox1.Text == "201700" && 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);
}
}
}
3.点击“退出”按钮则退出应用程序
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
五. 想一想,还有哪些尚需完善的功能
暂时没想到,技术不过关
// 在用户名输入框中按“回车”,光标跳转到密码输入框
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
SendKeys.Send("{tab}");
}
}
// Tab进入密码输入框时,自动全选密码
private void textBox2_Enter(object sender, EventArgs e)
{
((TextBox)sender).SelectAll();
}
网友评论