using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyStudentSys
{
public partial class Form1 : Form
{
Form2 form2 = new Form2();
Form3 form3 = new Form3();
public Form1()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text==""&&textBox2.Text=="")
{ MessageBox.Show("请输入用户名和密码!");
}
else
{
if (comboBox1.SelectedText.Equals("学生"))
{
string name = "admin"; string pass = "0000";
if (name == textBox1.Text.Trim() && pass == textBox2.Text.Trim())
{
form2.Show(); this.Hide();
}
}
else
{
string name = "admin"; string pass = "1111";
if (name == textBox1.Text.Trim() && pass == textBox2.Text.Trim())
{
form3.Show(); this.Hide();
}
}
} } private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("学生");
comboBox1.Items.Add("导师");
comboBox1.Items.Add("管理员");
comboBox1.SelectedIndex = 0;
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
} private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void textBox2_TextChanged(object sender, EventArgs e)
{ } }
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyStudentSys
{
public partial class Form1 : Form
{
Form2 form2 = new Form2();
Form3 form3 = new Form3();
public Form1()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text==""&&textBox2.Text=="")
{ MessageBox.Show("请输入用户名和密码!");
}
else
{
if (comboBox1.SelectedText.Equals("学生"))
{
string name = "admin"; string pass = "0000";
if (name == textBox1.Text.Trim() && pass == textBox2.Text.Trim())
{
form2.Show(); this.Hide();
}
}
else
{
string name = "admin"; string pass = "1111";
if (name == textBox1.Text.Trim() && pass == textBox2.Text.Trim())
{
form3.Show(); this.Hide();
}
}
} } private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("学生");
comboBox1.Items.Add("导师");
comboBox1.Items.Add("管理员");
comboBox1.SelectedIndex = 0;
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
} private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void textBox2_TextChanged(object sender, EventArgs e)
{ } }
}
改为
if (comboBox1.Text=="学生")
name.Equals(textBox1.Text.Trim()) && pass.Equals(textBox2.Text.Trim())
窗口的显示可以改成:
form2.ShowDialog();
另外开始用户名密码为输入的判断最好改成:
textBox1.Text.Trim().IsEmpty() || textBox2.Text.Trim().IsEmpty()1楼是对的,要学会自己调试的方法,可以准确判断是哪一句的问题。