http://blog.csdn.net/Knight94/archive/2006/08/22/1104957.aspx
http://blog.csdn.net/knight94/archive/2006/03/18/628285.aspx
参考了这两篇文章,但是没怎么看懂比如说主窗口F1,子窗口F2
F1中有个函数refDate(string strWhere)
在F2.ShowDialog()后,要将F2中的一些内容做为strWhere,并运行refDate

解决方案 »

  1.   

    F2.cs************************private F1 PaForm;
    public F2(F1 paForm)
    {
        PaForm=paForm;
    }private void button1_click()
    {
    PaForm.refDate(this....);
    }F1.cs************************private void refDate(string str)
    {

    }private void button1_click()
    {
    F2 f2=new F2(this);
    F2.ShowDialog;
    }
      

  2.   

    没看明白啥玩意。我自己给你写吧!主窗体代码
    public void refDate(string strWhere)
    {
      //do something
    }
    //添加一个按钮CLICK响应方法,显示子窗体
    private void btnAddUser_Click(object sender, EventArgs e)
    {
       Form2 fm2=new Form2();
       fm2.TestDelegate=this.refDate;
       fm2..ShowDialog();
    }
    父窗体://定义委托
    public delegate void NewDelegate(string strWhere);
    public NewDelegate TestDelegate;private void btnAddUser_Click(object sender, EventArgs e)
    {
       TestDelegate(strWhere);
    }
      

  3.   

    你在Form2中写公共变量StrWhere,strWhere,Form2关闭之前给strWhere赋值        private String strWhere = string.Empty;        public String StrWhere 
            {
                get
                {
                    return this.strWhere ;
                }
            }
    Form2关闭后运行取得Form2中的StrWhere字段就行了
                Form2 form2 = new Form2 ();
                form2.ShowDialog();
                refDate(form2.StrWhere);
      

  4.   

    举个简单例子
    窗体间传值(From2的Button事件将From2中的textbox1的text值传给From1的lable)
    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;//得到父窗体对象,之后可以用它操作父窗体了。
                ((Label)frm1.Controls["label1"]).Text = this.textBox1.Text;
                this.Close();  
      }   
      }  
      

  5.   

    功能可以实现
    但是是不规范代码,如果不是Form1调用Form2就会报错
      

  6.   

    你总说别人的不对,你没发现你把主窗体 this 直接扔过去,危险性多大么
    想想人家为什么用委托再说吧,,,还弯路,,晕……