在子窗口关闭同时,能过 自动 对父窗口里面一个文本控件进行指定的修改。(比如设置Label.Text=“111”)    这个事件该在哪设置?请帮忙讲解下   C#的消息事件不是很清楚,,,VC的倒是知道

解决方案 »

  1.   

    窗体的formClosed formClosing事件,两个有些区别,看楼主用哪个方便
      

  2.   


    public class FormChild:Form
    {
      public string LabelText
      {
         get;set;
       }
       BtnOK_Click()
       {
          LabelText = "aaa";
       }
    }
    public class ParentForm:Form
    {
       void ShowLable()
        {
           FormChild child = new FormChild();
            if (child.ShowDialg() == DialogResult.OK)
            {
               Label1.Text = child.LabelText;
            }
         }
      

  3.   

       private void button3_Click(object sender, EventArgs e)
            {            SubForm _SubForm = new SubForm ();
                _SubForm.FormClosing += new FormClosingEventHandler(_SubForm_FormClosing);
                _SubForm.Show();   
            }        void _SubForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                SubForm _SubForm=(SubForm)sender;
              //????
            }这样不行?
      

  4.   

    因为时间的关系,C#才学会1个星期,没去看自定义设置事件问题,
       应该有2种方法解决:一种是在父窗口注册子窗口的关闭事件
                          一种就是 bwangel  说的那样的方法,不过要补充一下,在子窗口里面添加:                  this.DialogResult = DialogResult.OK;
                    this.Close();
         补充下 : bwangel  开始哪些话是对1,2楼的2位说的   谢谢你的回答让我解决了问题
      

  5.   


    没有必要加这两句。只要你设定Form的AcceptButton为Btn_OK那个按钮,并设置它的返回值为OK就行了。