当前位置:编程学习 > C#/ASP.NET >>

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

C#  如何从一个窗口的控件控制另一个窗体上的控件的属性 --------------------编程问答-------------------- 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();  
  }  
  }  
--------------------编程问答-------------------- 牛人总是在的1楼回答,楼主是不是有没有看懂。 --------------------编程问答-------------------- 我看懂了。 --------------------编程问答-------------------- 为什么老和我抢分啊 --------------------编程问答-------------------- 将窗体对象作为一个参数传给另外一个窗体的构造方法 --------------------编程问答-------------------- 子窗体定义个全局变量,把要传的值给它
C# code

string 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; //这里把值就给这个文本框了
  }
--------------------编程问答-------------------- 我是菜鸟,我没看懂一楼的代码   
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,