按钮打开窗体,当它关闭时,它将更新原始窗体.需要帮忙! [英] Button Opens Form, when it closes it updates the original form. Need Help!

查看:55
本文介绍了按钮打开窗体,当它关闭时,它将更新原始窗体.需要帮忙!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过单击按钮来打开表单.我一直在寻找是否已打开该表格.但是,当它关闭时,我想刷新原始表单或父表单".需要帮忙!当我单击按钮时,我创建了一个无限循环,form5将永远不会加载!如何正确执行此操作?

I am trying to open a form with a button click. I am constantly looking to see if that form is opened. But when it closes, I want to refresh the original form or the "parent form". Need Help! When I click the button, I created an infinite loop which form5 will never load!. How can I do this properly?

WebBrowserForm form = new WebBrowserForm();
form.Show();
while (IsFormAlreadyOpen(typeof(Form5)))
{
}
refresh();


public Boolean IsFormAlreadyOpen(Type FormType){
            foreach (Form OpenForm in Application.OpenForms)
            {
                if (OpenForm.GetType() == FormType)
                    return true;
            }
            return false;



更新:

我的意思是我的原始form(1)有一个打开另一个form(2)的按钮.当form(2)关闭时,我希望对form(1)进行更新.



UPDATE:

I mean that my original form(1) has a button that opens another form(2). When form(2) closes, I want an update happen on form(1)

推荐答案

嗯,这当然是一种有趣的方法,但我没有推荐.您正在UI线程上的紧密循环中调用函数-因此,如何在Form5中进行处理(请重命名表单以使其有意义,请稍后记住什么表单做什么时会发生什么情况?)

不管怎样,更好的方法是在Form5中创建一个事件,并在调用表单中订阅它.在窗体关闭时引发此事件,然后在事件处理程序中调用refresh.
Well, this is certainly an interesting approach, but not one I''d recommend. You are calling a function in a tight loop on the UI thread - so, how can processing occur in Form5 (please rename your forms to be meaningful, what happens later on when you are trying to remember what form does what?)

Anyhoo, a better approach would be to create an event in Form5, and subscribe to it in the calling form. Raise this event when your form is closing and then call refresh in your event handler.


有两种形式的模式形式和无形式形式.只要模态表单是打开的,就不能使用打开它的表单(如果它位于同一应用程序中),因此没有必要检查第二个表单是否已经打开.

如果第二种形式是无模式的,则只需查看它是否已经创建,如果是,则显示它.完成后,将其隐藏或处置.

无论哪种情况,都可以在第一个表单中为第二个表单添加一个事件处理程序,以便它在第二个表单关闭时可以适当地响应.

现在,您的问题是什么?
There are two types of forms modal and modeless. As long as a modal form is open, the form that opened it (if it''s in the same apploication) cannot be used, so there''s no point in checking to see if the 2nd form is already open.

If the 2nd form is modeless, you simply need to see if it''s already created, and if so, show it. When you''re done with it, hide it or dispose it.

In either case, you can add an event handler for the 2nd form in your first form so that it can respon appropriately when the 2nd form closes.

Now, what''s your issue?


您好
你可以做到的

1.在父表单(例如"FrmMain")中,为示例form5创建类型为"Form5"的memebr;
2每次您需要打开此表单时都要执行此操作
Hello
you can do this

1 . in parent form for example "FrmMain" , create a memebr of type "Form5" for Example form5;
2 each time that you need to open this form do this
if(this.form5 ==null)
{
  this.form5 = new Form5();
  form5.FormClosing -= new FormClosingEventHandler(form5_FormClosing);
  form5.FormClosing += new FormClosingEventHandler(form5_FormClosing);
}
form5.Show();


并在此事件方法中执行所需的每项工作,例如刷新"当前表单


and in this event method do each work that you want for example "Refresh" current form

private void form5_FormClosing(object sender, FormClosingEventArgs e)
{
  this.Refresh();
  this.form5 = null;
}


如果这还不足以解决您的问题,那么可能会更复杂,例如使用Show()和Hide()方法


if this is not enough for you problem it can be more complex m for example use from Show() and Hide() methods


这篇关于按钮打开窗体,当它关闭时,它将更新原始窗体.需要帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆