在同一命名空间下,在一个Form2上如何访问Form1上的一个Button,我的目的只是想在另一个Form上改变button的一个属性。

解决方案 »

  1.   

    写一个属性返回这个button
    或者直接把访问权限设置为public
      

  2.   

    A窗体中:
    B frb=new (this.Button1);
    frb.ShowDialog();
    B窗体中:
    private Button btn;
    public B(Button BTN)
    {
    //
    // 
    btn=BTN;
    InitializeComponent(); // Add any initialization after the InitializeComponent() call
    }
    后面就可以对btn操作了,比如btn.Text="";
      

  3.   

    Form1上Button1为publicForm2 f = new Form2();
    f.Owner = this;
    f.Show();Form1 f1 = f.Owner as Form1
    f1.Button1.Text = "aaa"