窗体1 是列表窗体2 是添加窗体1 打开了 窗体2 窗体2 添加完成之后 刷新 窗体1怎么实现 谢谢..我曾今 在窗体2 使用
窗体1 f = new 窗体1();
f.刷新函数 但是不刷新为什么。而刷新函数在 窗体1执行就可以 

解决方案 »

  1.   

    我以前是做 webform 的 最近再试 winform所以不是很明白  请给出具体一点的代码
      

  2.   

    我曾今 在窗体2 使用 
    窗体1 f = new 窗体1(); 
    f.刷新函数 但是不刷新为什么。 而刷新函数在 窗体1执行就可以
    ---------------------
    窗体1 f = new 窗体1();  你又实例化一个窗体1
      

  3.   

    LZ把窗体2定义成dialog可能会更好处理一点吧
      

  4.   

    不用委托了。用ShowDialog()方法。然后返回。代码如下:
    MainFrom.cs /*
     * Created by SharpDevelop.
     * User: admin
     * Date: 2010-1-12
     * Time: 14:07
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;namespace ShowDialogForm
    {
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
    public MainForm()
    {
    //
    // The InitializeComponent() call is required for Windows Forms designer support.
    //
    InitializeComponent();

    //
    // TODO: Add constructor code after the InitializeComponent() call.
    //
    }

    void Button1Click(object sender, EventArgs e)
    {
    Form1 form1=new Form1();
    if(form1.ShowDialog()==DialogResult.OK)
    {
    MessageBox.Show(form1.Form1Str);
    }
    }
    }
    }
    Form1.cs主要代码/*
     * Created by SharpDevelop.
     * User: admin
     * Date: 2010-1-12
     * Time: 14:09
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    using System;
    using System.Drawing;
    using System.Windows.Forms;namespace ShowDialogForm
    {
    /// <summary>
    /// Description of Form1.
    /// </summary>
    public partial class Form1 : Form
    {
    private string form1Str;
    public Form1()
    {
    //
    // The InitializeComponent() call is required for Windows Forms designer support.
    //
    InitializeComponent();

    //
    // TODO: Add constructor code after the InitializeComponent() call.
    //
    }
    /// <summary>
    /// 获取Form1的值
    /// </summary>
    public string Form1Str
    {
    get
    {
    return form1Str;
    }
    }
    void Button1Click(object sender, EventArgs e)
    {
    form1Str="OK";
    this.DialogResult=DialogResult.OK;
    }

    void Button2Click(object sender, EventArgs e)
    {
    this.DialogResult=DialogResult.Cancel;
    }
    }
    }
      

  5.   

    form1 frm = this.parent as form1;
    if(frm = null)
    {
       frm.RefreshDataSource();
    }
      

  6.   


    在窗体1中:
     Form2 newForm = new Form2();
     newForm.ShowDialog();
     this.RefreshForm1()//刷新列表的方法
      

  7.   


    是两个平级窗体 不是parent 
      

  8.   

    yijianxiangde100 你这个是能获取到值。。 但是与我要的效果有差啊。。
      

  9.   

    既然是平行的,那你还是用#7的方法吧,不会存在什么效率问题,因为你那个form本来就开着,传过去的只是个地址