我想把登录窗体里的public 变量如 public  string username(用户名), public string power(用户权限)点击登录按钮后将值传递到给MDI窗体中的两个变量中如何实现?
请高手随便举个小例子!
在此先谢过!
急用

解决方案 »

  1.   

    把这两个变量放在某个类中。。
    用属性进行设置就行了。。
    Class 公共类
    {
     private string username;
     private string power;
     Public string UserName
    {
    get...
    set...
    }Public string Power
    {
    get...
    set...
    }
    }登录的时候:
    公共类.UserName=xxx
    公共类.Power=xxx大致是这样。。
      

  2.   

    winform用setting来设置,类似于web中的session一样
      

  3.   

    可以通过楼上写的通过他们的属性来访问
    或者你也可以将他们设置成static静态的
    public static string username(用户名), 
    在另个窗体通过类名.username来直接访问,但为了安全最好还是通过属性来访问
      

  4.   

    我没有用公共类,后来我想到这样弄也是可以,虽不是很好,但勉强可用)(跟3楼的方法类似):
    在登录窗体中
    public static string power;
    public static string username; 
    public string getp
            {
                get
                {
                 return power;
                }
            }
            public string getc
            {
                get
                {
                    return username;
                }
            }
    在mDI 窗体中:
    定义公共变量:登录窗体 f=null;
    在MDI load 事件中:
    f=new 登录窗体();
    然后用f.getp和f.getc得到所需参数。1楼min_jie 的回复,很好建议跟我一样遇到这个问题的同仁,用他的方法。很感谢,大家的热情回复!
      

  5.   

    我前不就也在考虑这问题:
    方法一:
    //在Form2中show窗体的代码,Form1中同理
    Form3 f3 = new Form3();
    f3.ShowDialog(this);
    //form3中这样写
    Form2 f2 = (Form2)this.Owner;
    Form1 f1 = (Form1)f2.Owner;
    //使用f1访问Form1公开的对象或方向就可以了
    f1.label1.Text="更新了";
    f1.更新方法();方法2:
    还有中就是mainform中 
    public void updataControl(string txt) 

        TextBox1.Text=txt; 
    } private void button1_Click(object sender, EventArgs e) 

        SubForm frmSub= new SubForm (); 
    //SubForm frmSub= new SubForm (this);//构造函数传对象     frmSub.frmMain= this; 
          frmSub.show(); 
    } 在SubForm public MainForm frmMain; private void buttonOK_Click(object sender, EventArgs e) 

              frmMain.updataControl (TextBox1.Text) ; 
      this.Close() 
      

  6.   

    用static来修饰,用类名.字段名来调用