如何卸载 VB.NET 中所有打开的表单?
在将 VB6 代码转换为 VB.NET 的过程中,我需要替换以下代码,该代码旨在关闭应用程序中剩余的所有打开的表单。
'close all sub forms
For i = My.Application.OpenForms.Count - 1 To 1 Step -1
'UPGRADE_ISSUE: Unload Forms() was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="875EBAD7-D704-4539-9969-BC7DBDAA62A2"'
Unload(My.Application.OpenForms(i))
Next i
我已将 Unload
函数替换为 Close
(如 TFM 所示),但编译器抱怨 OpenForms
不是 My.Application
的成员。
我在哪里可以访问开放表格?
In the middle of converting VB6 code to VB.NET, I need to replace the following code that intends to close all open forms remaining in the application.
'close all sub forms
For i = My.Application.OpenForms.Count - 1 To 1 Step -1
'UPGRADE_ISSUE: Unload Forms() was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="875EBAD7-D704-4539-9969-BC7DBDAA62A2"'
Unload(My.Application.OpenForms(i))
Next i
I've replaced the Unload
function with Close
(as indicated by TFM), but the compiler complains that OpenForms
is not a member of My.Application
.
Where can I access the open forms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
OpenForms
属性返回一个FormCollection
。 您可以遍历集合来处理所有表单。The
OpenForms
property returns aFormCollection
. You can iterate through the collection to process all forms.我发现了这个解决方案,
...看起来不错(如果不是冗长的话),一旦我可以编译其他所有内容,我就可以测试它。
I uncovered this solution,
...which looks alright (if not verbose), and I'll be able to test it just as soon as I can compile everything else..
Application.Exit 几乎会做同样的事情。
因为我想如果所有表单都关闭,您无论如何都想关闭应用程序。
Application.Exit will pretty much do the same.
AS I suppose you want to close the application anyway if all forms are closed.
My.Application.OpenForms 要求 VB.Net 应用程序使用应用程序框架(请参阅项目属性、应用程序、启用应用程序框架)。
如果您不使用应用程序框架,则可以使用 Application.OpenForms(来自 System.Windows.Forms 命名空间)。
The My.Application.OpenForms requires the VB.Net application to use the Application Framework (see Project Properties, Application, Enable Application Framework).
If you don't user the Application Framework, you can instead use the Application.OpenForms (from System.Windows.Forms namespace).
看看
Application.Windows< /code>
属性。
Have a look at the
Application.Windows
property.