1,界面设计如下
?2,源代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _08单选框1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text.Trim();
string password = textBox2.Text;
if(radioButton1.Checked)
{
if(name=="student"&&password=="student")
{
MessageBox.Show("学生登录成功");
}
else
{
MessageBox.Show("学生登录失败,请重新输入");
textBox1.Text = " ";
textBox2.Text = " ";
label1.Focus();
}
}
else if(radioButton2.Checked)
{
if (name == "teacher" && password == "teacher")
{
MessageBox.Show("老师登录成功");
}
else
{
MessageBox.Show("老师登录失败,请重新输入");
textBox1.Text = " ";
textBox2.Text = " ";
label1.Focus();
}
}
}
}
}
|