当用户登陆验证通过后,要调用一个新窗体,然后把登陆窗体给御掉,请问该怎样写?谢谢

解决方案 »

  1.   

    第二个窗体为NewForm,用户名text控件名为idText,密码text控件名为pswText
    在“确定”按钮的响应事件里:
    if(idText.Text == "id" & pswText.Text == "psw")
    {
    NewForm f = new NewForm();
    f.Show();
    this.Hide();
    }
      

  2.   

    为什么要卸载呢,直接调用就可以了;
    我感觉也 没有必要去隐藏他 Login Form=new Login();

    Form.StartPosition=FormStartPosition.CenterScreen;
        if(Form.ShowDialog()==DialogResult.OK)
         {  
    Form.Show();

         }
      

  3.   

    this.Hide()是可以隐藏掉,但是在系统里并没有真正清除,就像VB里一样,HIDE只是不可见,真正清除要用UNLOAD.
    三楼的"在原来的窗体上完成新页加载",请详细一些,本人以前用VB,现在初学C#,望指教.谢谢!
      

  4.   

    我认为这样做比较的好,你定义两个状态,在登陆的时候,显示状态1,登陆成功后,显示状态2,显示状态1和2通过Thread来完成调度,在显示状态1的时候,把状态2中用到的控件的visible值设置成false 就可以了.例如:
    using System.Threading;
    private void button2_Click(object sender, System.EventArgs e)
    {
    //调用zhuangtai5
    ZhuangTai=new Thread(new ThreadStart(zhuangtai5));
    ZhuangTai.Start();

    }
    //点击系统信息后的状态
    private void zhuangtai5()
    {
    string path = Application.StartupPath ;
    Ini ini = new Ini(path+"\\Set.ini");
    this.label9.Image=this.button2.Image;                               this.label9.Text="    "+this.button2.Text;
    this.button1.Enabled=true;
    this.textBox6.Text="";
    this.panel2.Visible=true;
    this.button2.Enabled=true;
    this.button3.Enabled=true;
    this.button4.Enabled=true;
    this.label11.Visible=false;
    this.textBox10.Visible=false;
    this.button5.Visible=false;
    this.button6.Visible=false;
    this.label12.Visible=false;
    this.button7.Visible=false;
    this.label13.Visible=false;
    this.label14.Visible=false;
    this.label15.Visible=false;
    this.label16.Visible=false;
    this.label18.Visible=false;
    this.label19.Visible=false;
    this.label20.Visible=false;
    this.label21.Visible=false;
    this.textBox14.Visible=false;
    this.textBox11.Visible=false;
    this.textBox12.Visible=false;
    this.textBox13.Visible=false;
    this.button8.Visible=false;
    this.button9.Visible=false;
    this.button10.Visible=false;
    this.button11.Visible=false;
    this.textBox15.Visible=false;
    this.textBox16.Visible=true;
    this.textBox17.Visible=true;
    this.textBox18.Visible=true;
    this.textBox19.Visible=true;
    this.button12.Visible=true;
    this.label26.Visible=true;
    this.button13.Visible=true;
    this.label27.Visible=true;
    this.button14.Visible=true;
    this.label28.Visible=true;
    this.button15.Visible=true;
    this.label29.Visible=true;
    this.label30.Visible=true;
    this.label31.Visible=true;
    this.label32.Visible=true;
    this.label33.Visible=true;
    this.label34.Visible=true;
    this.label30.Text=ini.IniReadValue("CPUInfo","CpuN");
    this.label31.Text=ini.IniReadValue("CPUInfo","CpuT");
    this.label32.Text=ini.IniReadValue("CPUInfo","CpuS");
    this.label33.Text=ini.IniReadValue("CPUInfo","CpuI");
    this.label34.Text=ini.IniReadValue("CPUInfo","CpuB");

      

  5.   

    我一般也用的是类似eros_wz(丁丁)的方法
      

  6.   

    把main放在主窗口中,在main中load登陆窗口,验证通过则运行主窗口,这时就可以卸下登陆窗口,如果把main放在登陆窗口,你的登陆窗口就不能直接卸,卸了程序就结束了。
      

  7.   

    我的做法跟楼上(小朱)的一样,把主窗口当成MainForm,然后运行程序的时候用ShowDialog打开登录窗口,这样就会先显示登录窗口了
      

  8.   

    估计三楼的没看清题目,以为在说WEBFORM
      

  9.   

    这个是连接 access 验证用户登陆的
    private void button1_Click(object sender, System.EventArgs e)
    {
    if (textUser.Text=="" || textPass.Text=="" )
    {
    string msg="用户名、密码不能为空!";
    MessageBox.Show(msg,"提示");
    return;
    }
    string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = chillcoder.mdb " ;
    OleDbConnection chkconn = new OleDbConnection(strCon);
    string testsql="select count(*) from cc_admin where username='"+textUser.Text.ToString()+"'and password='"+textPass.Text.ToString()+"'"; chkconn.Open();
    OleDbCommand chkcmd = new OleDbCommand(testsql,chkconn);
    int Count=(int)chkcmd.ExecuteScalar();
    chkconn.Close();
    if(Count==0)
    {
    MessageBox.Show("没有这个用户!请核对您是否输入正确!","提示!");
    textUser.Text="";
    textPass.Text="";
    return;
    }
    try
    {
    this.Hide();
    MainForm frm=new MainForm();
    frm.ShowDialog();
    frm.Dispose();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    } }
      

  10.   

    我有一个与本题相反的问题,我是退出时登录权限界面,用户名和密码正确就连主界面一起退出,我在权限的界面代码是
    public bool UserCanCannel = false;    //用户有退出权限
    public frmSystemMain CloseForm;
    private void butOk_Click(object sender, EventArgs e)
    {
    if (textBox1.Text == "")
    {
    MessageBox.Show("用户名称不能为空!");
    }
    else
    {
    switch (textBox1.Text)
    {
    case "001":
    if (textBox2.Text != "002")
    {
    MessageBox.Show("密码不正确!请重新输入!");
    }
    else
    {
    UserCanCannel = true;
    }
    break;
    case "RECON_E":
    if (textBox2.Text != "E_RECON")
    {
    MessageBox.Show("密码不正确!请重新输入!");
    }
    else
    {
    UserCanCannel = true;
    }
    break;
    }
    }
    if (UserCanCannel)
    {
    this.Visible = false;
    this.Close();
    CloseForm.Close();
    }

    }
    运行程序时CloseForm.Close();这个报错,请高手解释解释,并且希望告诉实现方法!谢谢!