C#  如何从一个窗口的控件控制另一个窗体上的控件的属性

解决方案 »

  1.   

    public partial class Form1 : Form  
      {  
      private void button1_Click(object sender, EventArgs e)  
      {  
      Form2 frm2 = new Form2();  
      frm2.Show(this);  
      }  
      }    public partial class Form2 : Form  
      {  
      private void button1_Click(object sender, EventArgs e)  
      {  
      Form1 frm1 = (Form1)this.Owner;  
      ((TextBox)frm1.Controls["textBox1"]).Text = this.textBox2.Text;  
      this.Close();  
      }  
      }  
      

  2.   

    子窗体定义个全局变量,把要传的值给它
    C# codestring m_ProID = "";
        
      public string ProID
      {
      set { this.m_ProID = value; }
      get { return this.m_ProID; }
      }父窗体弹出子窗体按钮的时间里写Form2 f2 = new Form2();
      if (DialogResult.Abort == f2.ShowDialog(this))  
      {
      return;
      }  if (f2.ProID != "" && f2.ProID != null)
      {
      this.txtProjectID.Text = f2.ProID; //这里把值就给这个文本框了
      }