我在一个窗口内点击一个按扭弹出一个新窗口
private void button2_Click(object sender, EventArgs e)
        {
            SelfDesign sdfrm = new SelfDesign();
            sdfrm.ShowDialog();
        }
在新窗口设定几个值之后,我将this.Visible = false;返回原来窗口怎么将原来的窗口刷新呢?,
要求在将this.Visible = false的同时,刷新原窗口...

解决方案 »

  1.   

    “要求在将this.Visible = false的同时,刷新原窗口”
    都隐藏了还刷新,为什么啊?能不能等到再显示时刷新。另外,窗口是用户界面,业务逻辑不用在界面体现,只用来输出。
      

  2.   

    ShowDialog时,父窗体的执行就停止了,一直到子窗体关闭才会继续,所以更新代码就可以写在这后面。
      

  3.   

    直白一些吧,下面是更改客户端配置的示例,指定要登陆的服务器 ConfigForm configForm = new ConfigForm(strUserName, strPwd);
                configForm.StartPosition = FormStartPosition.CenterScreen;
                configForm.ShowDialog();
                if(configForm.bUpdate)
                {
                    m_ConfigIniFile.WriteString("SYSTEM", "SERVERIP", configForm.strIP);
                    m_ConfigIniFile.WriteString("SYSTEM", "SERVERPORT", configForm.strPort);
                }下面是子窗口中输入服务器IP,port
           private void btUpdate_Click(object sender, EventArgs e)
            {
                strIP = txtIP.Text;
                strPort = txtPort.Text;
                try
                {
                    System.Net.IPAddress.Parse(strIP);
                    Convert.ToInt32(strPort);
                    System.Net.IPAddress.Parse(strMSIP);
                }
                catch (System.Exception eConfig)
                {
                    eConfig.ToString();
                    MessageBox.Show("请检查IP地址及端口格式。\n", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                bUpdate = true;
                this.Close();
            }关闭窗口子窗口的实例还在,可以直接调用其中变量。
      

  4.   

    谢谢johndii,你的代码非常 有用...解决了这个问题 额,再问一下
     Button button = new Button();
                    button.Size = new Size(80, 20);
                    button.Text = "OK";
                    button.Location = new Point(10, 10);
                    groupBox1.Controls.Add(button);我添加一个按扭,怎么添加他的点击事件啊?
      

  5.   

    再直白点
     button.Click += new System.EventHandler(button_Click);private void button1_Click(object sender, EventArgs e)
            {
               MessageBox.Show("点击事件");
            }
      

  6.   

    Button button = new Button();
      button.Size = new Size(80, 20);
      button.Text = "OK";
      button.Location = new Point(10, 10);
      groupBox1.Controls.Add(button);
    Button.Click += new System.EventHandler(button_Click);private void button1_Click(object sender, EventArgs e)
    {
    MessageBox.Show("这就是你创建新按钮的事件");
    }
      

  7.   


    刚才试了一下,可以
    不过,还有一个问题,因为按扭是动态生成 的,不知道个数啊,Button.Click += new System.EventHandler(button_Click);
    这里面的button_Click怎么写啊
    按扭不是调用同一事件啊