我现在有两个窗体,一个是登陆框,一个是主窗体,现在我想在登陆成功登陆框关闭之后传递一个信息给主窗口已经登陆成功,并传递一个参数给主窗体,怎么给这两个窗体之间进行通信啊?
还有一个问题,代码如下:
public partial class 登陆 : Form
    {
        int i = 1;//计数器
        public 登陆()
        {
            InitializeComponent();
        }        private void btnLogin2_Click(object sender, EventArgs e)
        {
            string path1 = "d:\\";
            string path2 = string.Concat(txtName2 .Text , ".txt");
            string path3 = Path.Combine(path1, path2  );
            //string fileName;
            string password;
            
            try
            {
                FileStream fs = new FileStream(path3, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                if ((password = sr.ReadLine()) != "")
                {
                    if ((password = sr.ReadLine()) == textBox2.Text)
                    {
                        MessageBox.Show("您已经成功登陆!", "祝贺您", MessageBoxButtons.OK, MessageBoxIcon.Information);                        this.Close();
                    }
                    else
                    {
                        if  ((password = sr.ReadLine()) != textBox2.Text && i < 3)
                        {
                            MessageBox.Show("您的密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            i = i++;
                        }
                        else if  ((password = sr.ReadLine()) != textBox2.Text && i >= 3)
                        {
                            MessageBox.Show("您已经输入超过三次,系统将自动关闭", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                            Form1 f = new Form1();
                            f.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Stop);            }
        }
运行之后我输错3次以上密码,智慧出现提示密码错误的窗口,没有出现第三种情况,请问这是怎么回事,应该怎么做?

解决方案 »

  1.   

    form1里面定义一个public的变量 flag
    Form1   f   =   new   Form1(); 
    f.flag = true;
    ......
      

  2.   

    你所说的第三种情况是什么意思?是说你的主窗口没有关闭吗?
    Form1   f   =   new   Form1(); 
    f.Close(); 这里你创建了一个新的Form1,然后把它关了
    而不是关闭你原有的主窗口
      

  3.   

    第三种情况就是我输了几次错误的密码,但那个
    else   if     ((password   =   sr.ReadLine())   !=   textBox2.Text   &&   i   > =   3) 
                                                    { 
                                                            MessageBox.Show("您已经输入超过三次,系统将自动关闭",   "警告",   MessageBoxButtons.OK,   MessageBoxIcon.Information); 
                                                            this.Close(); 
                                                            Form1   f   =   new   Form1(); 
                                                            f.Close(); 根本就没有执行,一直都是提示密码错误,请问这是怎么回事啊?
      

  4.   

    1》我在form1.cs中申明了public bool isLogin = false;但我在登陆.cs中无法调用他啊,怎么回传是否登陆成功呢?
    2》怎么申明全局变量啊,在program.cs里?
    3》我在form1.cs中输入is也无法枚举出isLogin,这个变量申明的有问题吗?
    4》5楼说的我知道了,那怎么在登陆里关掉主窗口呢?麻烦大家了!
      

  5.   

    当然是代码逻辑错误啊!
    if     ((password   =   sr.ReadLine())   !=   textBox2.Text   &&   i   <   3) 
    密码不对并且i<3;
    表达式错误!!
    csharp里边的算符优先级,你再查一查!&&优先级大于!=
    你的表达式相当于((password   =   sr.ReadLine())   !=   (textBox2.Text   &&   i   <   3))
    怎么改就不用我说了!
      

  6.   

    对于验证不成功的,你可以直接关闭程序就行,没有必要让form1来关闭自己!
    form1关闭登录,你可以在form1里设置变量
    pubic 登录 first;
    然后再form1得构造函数里加上
    public form1(登录 s)
    {
    first=s;
    }
    通过验证后,在form1里把登录窗口隐藏起来,这种方法最好,因为你的form1是登录类的一个函数的局部变量,一旦登录没有了,估计form1也就不行了!
      

  7.   

    http://blog.csdn.net/chenyuling/archive/2007/05/25/1625907.aspx
      

  8.   

      FORM1------父窗口   
      BUTTON1------FORM1上的按扭   
      FORM2-----子窗口   
      BUTTON2-----FORM2上的按扭   
      如何实现单击BUTTON1后显示FORM2   
      然后单击BUTTON2后把BUTTON1的ENABLE属性变成FALSE;(原为TRUE) Form2   
        
      public   delegate   void   delegate_SetBtProperty(bool _Enable);   
      public   delegate_SetBtProperty   SetBtProperty;   
        
      private   void   button2_Click(object   sender,   System.EventArgs   e)   
      {   
              SetBtProperty(false);   
      }   
        
      _____________________________________   
      Form1   
        
      private   void   button1_Click(object   sender,   System.EventArgs   e)   
      {   
              Form2   fr2=new   Form2();   
        
              fr2.SetBtProperty=new   WindowsApplication1.Form2.delegate_SetBtProperty     (SetBt2Property);   
              fr2.Show();   
      }   
        
      public   void   SetBt2Property(bool   _Enable)   
      {   
              this.button1.Enabled=_Enable;   
      }