01windows窗体程序学习

时间:2021-12-01 04:47:44

静态用户名和密码的登录练习

private void button2_Click(object sender, EventArgs e)   
{

textUser.Text = Convert.ToString(textUser.Text);
textBox2.Text = textBox2.Text.ToString();
if (textUser.Text == "admin" && textBox2.Text == "111111")
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("用户名或密码错误");
}

}

窗体关闭消息提示的练习

private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult re = MessageBox.Show("确定关闭?","消息",MessageBoxButtons.YesNo);//是否关闭消息提示框
if (re == DialogResult.No)
{
e.Cancel = true; //关闭
}
else
{
e.Cancel = false; //不关闭
}
}

01windows窗体程序学习