如何卸载 VB.NET 中所有打开的表单?

发布于 2024-07-14 09:02:20 字数 553 浏览 10 评论 0原文

在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

茶花眉 2024-07-21 09:02:20

OpenForms 属性返回一个FormCollection。 您可以遍历集合来处理所有表单。

For each f as Form in My.Application.OpenForms
 f.Close()
Next

The OpenForms property returns a FormCollection. You can iterate through the collection to process all forms.

For each f as Form in My.Application.OpenForms
 f.Close()
Next
時窥 2024-07-21 09:02:20

我发现了这个解决方案,

'close all sub forms
For i = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1
    Dim form As Form = System.Windows.Forms.Application.OpenForms(i)
    form.Close()
Next i

...看起来不错(如果不是冗长的话),一旦我可以编译其他所有内容,我就可以测试它。

I uncovered this solution,

'close all sub forms
For i = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1
    Dim form As Form = System.Windows.Forms.Application.OpenForms(i)
    form.Close()
Next i

...which looks alright (if not verbose), and I'll be able to test it just as soon as I can compile everything else..

过度放纵 2024-07-21 09:02:20

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.

无敌元气妹 2024-07-21 09:02:20

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).

森罗 2024-07-21 09:02:20

Have a look at the Application.Windows property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文