从另一个打开的表单刷新打开的表单 [英] Refresh an open form from another open form

查看:296
本文介绍了从另一个打开的表单刷新打开的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个打开的窗体( form2 )button_click()刷新已经打开的窗体( form1 )。在 form1 中显示由 form2 保存的数据,当 form1 已经打开时,如果新数据保存在 form2 为了显示它。



问题是我尝试了通过`Application.Openforms`迭代,但事实证明它被读取 - 一次,我无法访问表单一旦找到,我不知道如何从* form2 * * form1 *,因为我不能简单地找到它。



如何从* form2 *访问* form1 *?



编辑:

Form1实际上是从Form2打开的。

Application.Openforms的问题在于,正如我所说的,已经打开了一个只读的表单列表,我实际上无法通过它访问这些表单。他们根本没有它的方法,我试图使用Application.OpenForms,并查看它,如果你不知道它是如何工作的。
另外显示我已经尝试过的内容是毫无意义的,因为它包含 Application.OpenForms ,但为了提供信息:

  FormCollection of = Application.OpenForms; 
foreach(var f in)
{
if(f.GetType()。ToString()==Kontrl_Doc.Visualizar)
{
f。刷新();


当我点击按钮(button_click()) Form2它检查Form1是否打开。如果Form1没有打开,它会打开一个,如果它比我想刷新它。同时,它关闭Form2并再次打开Form2,以重置字段。



我想要做的是,如果form1已经打开, form2应该告诉它用表单1刷新已经打开的窗口。

可以使用事件。在form2中,你放置这段代码

 公共事件Action ReloadForm1; 

//你将重新加载的地方form1
ReloadForm1();

,如果您打开form2,则在form1中:

  form2.ReloadForm1 + =重新加载; 
$ b $ // //外部方法
void重新加载()
{
this.Reload();
}


I want to refresh an already opened form (form1) from another opened form's (form2) button_click(). In form1 I display the data saved by form2 and when form1 is already opened I want it to refresh if new data is saved on form2 in order to display it.

The problem is that I've tried iterating through `Application.Openforms`, but it turns out that it is read-only and I cannot access the form once found and I don't know how to access *form1* from *form2*, since I can't simply find it.

How can I access *form1* from *form2*?

Edit:

Form1 is actually opened from Form2.

The problem with Application.Openforms is that , as I've stated, a read-only list of forms already opened and I cant actually access the forms through it. They simply don't have the methods for it, I sugest you try using Application.OpenForms and look it up if you don't know how it works. Also it's pointless to show what I've already tried because it includes Application.OpenForms, but for the sake of information:

FormCollection of = Application.OpenForms;
                foreach (var f in of)
                {
                    if (f.GetType().ToString() == "Kontrl_Doc.Visualizar")
                    {
                        f.Refresh();
                    }
                }

When I click the button (button_click()) in Form2 it checks if Form1 is open or not. If Form1 isn't open it opens one and if it is than I'd like it to refresh it. Simultaneously, it closes Form2 and opens Form2 again, in order to reset is fields.

What I wan to do is, if the form1 is already opened , it form2 should tell it to refresh the already opened window with the form 1.

解决方案

you can use events. In form2 you place this code

public event Action ReloadForm1;

//on the place where you will reload form1
ReloadForm1();

and in form1 if you have opening form2:

form2.ReloadForm1 += Reload;

//outside method
void Reload()
{
    this.Reload();
}

这篇关于从另一个打开的表单刷新打开的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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