如题!

解决方案 »

  1.   

    登陆验证成功后,记录一个状态:Bool LoginState = true;记录后关闭登陆窗体 
    在Program.cs改为: 
    LoginForm  login= new LoginForm(); 
    if(LoginState ) 
      Application.Run(new MainForm()); 
      

  2.   

    不好意思。没看清楚。
                Form2 f = new Form2();
                f.Show();
                this.Hide();
    form2为你的主界面。this为你的登录窗口
      

  3.   

    楼上的朋友,Hide()了可是还是在运行啊,只是说看不到界面了而已!
    你一直用这种方法?
      

  4.   

    恩请问有什么好的方法吗?不是改动program文件
      

  5.   


            static void Main()  
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 f1 = new Form1(); //登录窗体
                f1.ShowDialog();
                if (f1.y == true)       //根据输入的打开窗体 根据不同权限进入窗体
                {
                    Application.Run(new FormAdmin("1"));
                }
                if (f1.x == true)
                {
                    Application.Run(new FormAdmin());
                }
                if (f1.z == true)
                {
                    Application.Run(new FormAdmin(1));
                }
            }
            public bool y = false;      //登录窗体定义变量
            public bool x = false;    
            public bool z = false;
            public Form1()
            {
                InitializeComponent();
                StartPosition = FormStartPosition.CenterScreen; 
            }
            private void button1_Click(object sender, EventArgs e)
            {
                string a = this.textBox1.Text;
                string b = this.textBox2.Text;
                string c = this.comboBox1.Text;
                database db = new database();
                string sql="select * from admin where entername='"+a+"'and userpassword='"+b+"' and userrole='"+c+"'";
                SqlDataReader sqlrd=db.read(sql).ExecuteReader();
                if (!sqlrd.Read())
                {
                    MessageBox.Show("用户名或密码或用户角色输入错误!");
                    this.textBox1.Text = "";
                    this.textBox2.Text = "";
                }
                else if (c == "标准维护人")
                {
                    x = true;
                    this.Close();
                }
                else if (c == "普通用户")
                {
                    y = true; 
                    this.Close();
                }
                else if (c == "标准发布人")
                {
                    z = true;
                    this.Close();
                }        }      
      

  6.   

    我这个方法不用Hide()隐藏。修改program文件里面,手动打开登录窗体,然后根据登录窗体的值打开主窗体并关闭登录窗体!绝对好用。LZ给分吧
      

  7.   

    ?你这是什么问题?我告诉你我的方法。程序启动的时候 Application 里面new 的是一个登录窗体,登录后,再去new 主窗体……
      

  8.   

    刚学c#
    来学习,不是不能关闭主窗体吗?我们教员教得一直是this.visible = false;
    这样的行不?
      

  9.   

    有谁能说一下使用hide()方法与操作program.cs文件那个占用内存小一点?