隐藏和显示代码不适用于其他形式
Hide and Show Code doesnt work on other forms
形式 1
public void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\ALLENSQL;Initial Catalog=TITOMSLogin;Integrated Security=True");
SqlDataAdapter sdf = new SqlDataAdapter("select usertype, fullname, position from login where username= '" + txtuser.Text + "' and password='" + txtpass.Text + "'", con);
DataTable dt = new DataTable();
sdf.Fill(dt);
string fullname = dt.Rows[0]["FullName"].ToString();
string position = dt.Rows[0]["Position"].ToString();
if (dt.Rows.Count == 1)
{
this.Hide();
if (dt.Rows[0]["Usertype"].ToString() == "Admin")
{
Form2Admin ss = new Form2Admin(position + ": " + fullname);
Form3Admin sa = new Form3Admin(position + ": " + fullname);
Form5 sw = new Form5(position + ": " + fullname);
ss.Show();
sa.Hide();
sw.Hide();
}
现在此代码不适用于其他形式
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form3Admin.Show();
}
这是我想要实现的场景:
- 点击登录后form2会出现,form 3和form 4被隐藏。
- 按下表单 2 中的按钮(表单 2 将隐藏,表单 3 将显示)。
- 按下表单 3 中的按钮(表单 3 将隐藏,表单 4 将显示)。
- 表单4中的按钮被按下(表单4会隐藏,表单2会显示但之前写入的所有数据必须仍然存在)等等其他表单。
您必须使用相同的实际 Form3Admin
实例来显示它。将 Form3Admin sa
实例保留为 class 变量,并在需要显示时使用该实例。
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
sa.Show();
}
形式 1
public void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\ALLENSQL;Initial Catalog=TITOMSLogin;Integrated Security=True");
SqlDataAdapter sdf = new SqlDataAdapter("select usertype, fullname, position from login where username= '" + txtuser.Text + "' and password='" + txtpass.Text + "'", con);
DataTable dt = new DataTable();
sdf.Fill(dt);
string fullname = dt.Rows[0]["FullName"].ToString();
string position = dt.Rows[0]["Position"].ToString();
if (dt.Rows.Count == 1)
{
this.Hide();
if (dt.Rows[0]["Usertype"].ToString() == "Admin")
{
Form2Admin ss = new Form2Admin(position + ": " + fullname);
Form3Admin sa = new Form3Admin(position + ": " + fullname);
Form5 sw = new Form5(position + ": " + fullname);
ss.Show();
sa.Hide();
sw.Hide();
}
现在此代码不适用于其他形式
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form3Admin.Show();
}
这是我想要实现的场景:
- 点击登录后form2会出现,form 3和form 4被隐藏。
- 按下表单 2 中的按钮(表单 2 将隐藏,表单 3 将显示)。
- 按下表单 3 中的按钮(表单 3 将隐藏,表单 4 将显示)。
- 表单4中的按钮被按下(表单4会隐藏,表单2会显示但之前写入的所有数据必须仍然存在)等等其他表单。
您必须使用相同的实际 Form3Admin
实例来显示它。将 Form3Admin sa
实例保留为 class 变量,并在需要显示时使用该实例。
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
sa.Show();
}