繁体   English   中英

如何自动关闭对话框?

[英]How to automatically close the dialog box?

我有一个 WinForm 应用程序,它在一段时间后没有用户执行活动的情况下会自动注销,该应用程序有一些对话框,例如

SearchCustomer.ShowDialog()

如果用户让该对话框保持打开状态并且时间到期,则用户将自动注销,但该对话框保持打开状态,因此即使用户注销,任何人都可以使用该对话框。

有什么办法可以从主窗体关闭这些对话框?

编辑:有另一个对话框以不同的方式打开

AddCustomer.Show()
AddCustomer.BringToFront()

根据 jmcilhinney 答案编辑 2解决方案

For Each openForm In openForms

    Dim H1 As Integer = openForm.GetHashCode()
    Dim H2 As Integer = Me.GetHashCode()
    If H1 <> H2 Then 'No igual
       openForm.Close()
    End If
Next

我还没有测试过,但我认为你应该能够按照以下方式做一些事情:

Dim openForms = My.Application.OpenForms.Cast(Of Form)().ToArray()

For Each openForm In openForms
    openForm.Close()
Next

这是一个选项。

使用所有权属性打开您的表单。

    AddCustomer.Show(Me)
    'This open the form and gives the referring form ownership.
    'It Also gives focus to the child form, keeping it on top of the referring form

当引用表单关闭时,子表单也关闭。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM