比如:在主窗体的菜單上調用子窗体的一個保存數据的方法,是否要用delegate,怎么用謝謝!

解决方案 »

  1.   

    1、可以在子窗体中添加事件,在主窗体中处理事件。
    用button的click示例,代码如下:
    public class ChildForm : System.Windows.Forms.Form
    {
      //
      public event EventHandler BtnClick;
      //
      private void button1_Click(object sender, System.EventArgs e)
      {
        if(this.BtnClick != null)
        {
          this.BtnClick(sender,e);
        }
      }
    }public class MainForm : System.Windows.Forms.Form
    {
      private void button1_Click(object sender, System.EventArgs e)
      {
        ChildForm cldForm = new ChildForm();
        cldForm.BtnClick+= new BtnClick(MainForm_BtnClick); 
      }
    }2、在ChildForm中设置公有Button,
    代码如下
    public Button button1;
    在MainForm中绑定button1的Click事件3、将ChildForm作为参数传递给MainForm,在MainForm中直接调用ChildForm中的方法。