[英]Closing multiple new form [VB.NET]
I have a problem with my sw: i have three forms: the main form(A), a secondary form (B) and third form (C). 我的sw有问题:我有三种形式:主形式(A),次要形式(B)和第三种形式(C)。 The form A must be always visibile and usable, the form B opening from form A and the form C opening form the form B. I need to open multiple instance of form C (i do not know how much instance are), i'm using this code in a command button on form B:
表单A必须始终可见且可用,表单B从表单A打开,表单C从表单B打开。我需要打开表单C的多个实例(我不知道实例数),我是在表单B的命令按钮中使用以下代码:
Dim newform As New modifica_normale
newform.LoadOrders(commessa_da_modificare, id_da_modificare, False)
newform.Show()
When the form B is close i need to close all of multiple instance of form C, so in the closing event i've tried to put: 当窗体B关闭时,我需要关闭窗体C的所有多个实例,因此在关闭事件中,我尝试放置:
modifica_normale.Close()
but do not work. 但不起作用。 I know that i can define newform as global variable and call newform.close(), but i don't know the number of newform that the user will open.
我知道我可以将newform定义为全局变量并调用newform.close(),但是我不知道用户将打开的newform数量。
Thanks, Pietro. 谢谢,彼得罗。
This code will only close the common instance of the form and not each newly instantiated form object: 此代码将仅关闭表单的公共实例,而不关闭每个新实例化的表单对象:
modifica_normale.Close()
Instead you could try adding the forms to a forms collection as you create each form. 相反,您可以尝试在创建每个表单时将表单添加到表单集合中。 Create a form level list on form B.
在窗体B上创建一个窗体级别列表。
Dim currentForms As List(Of Form) = New List(Of Form)
Add to it each time an instance of form C is created 每次创建表单C的实例时将其添加
Dim fNew As New modifica_normale
currentForms.Add(fNew)
When you want to close them, loop back through the forms collection closing each instance. 当您要关闭它们时,请循环返回关闭每个实例的表单集合。
For Each frmCheck As Form In currentForms
frmCheck.Close
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.