form1 中的空间有textbox1 和button
点击button 弹出borm2,如何在form2中操作form1中的textbox1

解决方案 »

  1.   

    用自定义事件再处理:
    事件类:
    public delegate void EventFroIE(string id);
    public class EventTest
    {
    public static EventTest Instance;
    public event EventFroIE EventChangeUrl;
    public virtual void OnEventChangeUrl(string id)
    {
    if(EventChangeUrl!=null)
    EventChangeUrl(id);
    }
    static  EventTest()
    {
    Instance =new EventTest();
    }
    public EventTest()
    {
    }
    public void ToChangeUrl(string id)
    {
    OnEventChangeUrl(id);
    }
    }
    form1:
    InitializeComponent();
    EventTest.Instance.EventChangeUrl+=new EventFroIE(Instance_EventChangeUrl);
    private void Instance_EventChangeUrl(string id)
    {
    textBox1.Text=id;
    }
    form2:
    private void button1_Click(object sender, System.EventArgs e)
    {
    EventTest.Instance.ToChangeUrl("aa");
    }
      

  2.   

    以前写的文章,
    http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
      

  3.   

    Form2中的代码
    public static void TextB(TextBox txt)
    {
      txt.text = "";
    }
    Form1中的代码
    Form2. TextB(this.textBox1);
    在Form2中定义一个全局的静态的方法,在FORM1里面实例化为textBox1