获取另一个窗体中打开的窗体实例的引用? [英] Get a reference to an opened instance of a form from another form?

查看:69
本文介绍了获取另一个窗体中打开的窗体实例的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我这里有一个关键问题,我需要一些帮助.

我有一个打开的表单"Form1",其中包含标签"Label1",我还有另一个表单"Form2",其中包含一个按钮"Button2".我需要做的是获取对Form1的打开实例的引用,以便我可以更新Label1的属性,并通过Form2中的Button2_Click事件使它不可见.

在Vb,Net 2005中是否可行?


请指教,

在此先感谢....

Greetings,

I have a critical issue here and I want some help.

I have an open form "Form1" that contains a label "Label1" and I have another form "Form2" that contains a button "Button2". What I need to do is to get a reference to the opened instance of Form1 so that I can update the attributes of Label1 and also make it invisible through the Button2_Click event in Form2.

Is this possible or not in Vb,Net 2005?


Please advise,

Thanks in advance....

推荐答案

是的,您可能需要在form2中创建Form1的对象.
前任.
Yes possible you need to create an Object of Form1 in form2.
ex.
dim objectname as form1


并在Form2.as中访问form1的label1
例如


and access label1 of form1 in Form2.as
ex.

objectname.label1.text="Text"


并在form1中添加任何要Label1的内容.


and make anything you want to Label1 in form1.


谢谢大家,

我自己得到了解决方案,我将在这里展示给任何人以使用它.

我们在这里:

Form1已打开
Form1包含Label1
表格2
Form2包含Button2

然后在Form1的Load事件中,我们编写以下代码:

将pForm2视作新的Form2
如果pForm2.ShowDialog = OK,则
Label1.Visible = False
如果结束


请与我联系以获取更多详细信息,
Thanks Guys,

I got the solution myself and I will show it here for anyone to get benefit of it.

We have here:

Form1 is opened
Form1 contain Label1
Form 2
Form2 contain Button2

Then at the Load event of Form1 we write the following code:

Dim pForm2 as New Form2
If pForm2.ShowDialog=OK then
Label1.Visible=False
End If


Please contact me for any further details,


这篇关于获取另一个窗体中打开的窗体实例的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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