7.WinFor練習--用戶登錄

namespace _7用戶登錄
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//點擊登錄時進行判斷
private void btnLoging_Click(object sender, EventArgs e)
{
if (radStudent.Checked || radTeacher.Checked)
{
//取得輸入用戶名和密碼
string name = txtName.Text.Trim();
string pwd = txtPwd.Text;
//判斷學生登錄還是老師登錄
if (radStudent.Checked)
{
if (name == "student" && pwd == "student")
{
MessageBox.Show("學生登錄成功");
}
else
{
MessageBox.Show("學生登錄失敗");
txtName.Clear();
txtPwd.Clear();
txtName.Focus();
}
}
else
{
if (name == "teacher" && pwd == "teacher")
{
MessageBox.Show("老師登錄成功");
}
else
{
MessageBox.Show("老師登錄不成功");
txtName.Clear();
txtPwd.Clear();
}
}
}
else
{
MessageBox.Show("請先選擇用戶登錄身份");
}
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章