Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 检查是否有任何对话框打开_Vb.net_Winforms - Fatal编程技术网

Vb.net 检查是否有任何对话框打开

Vb.net 检查是否有任何对话框打开,vb.net,winforms,Vb.net,Winforms,有人看到我的错误了吗 我无法识别表单是否在我的应用程序中显示为对话框 Public Class Form1 Private m As Form2 Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Me.Text = DateTime.Now.ToLongTimeString & " " & IsAnyDialogShown()

有人看到我的错误了吗

我无法识别表单是否在我的应用程序中显示为对话框

Public Class Form1

  Private m As Form2

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    Me.Text = DateTime.Now.ToLongTimeString & " " & IsAnyDialogShown()
  End Sub

  Public Function IsAnyDialogShown() As Boolean
    For Each f As Form In Me.OwnedForms
       If f.Owner Is Me Then
         Return True
       End If
    Next
  End Function

  Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    m = New Form2
    m.ShowDialog()
  End Sub

End Class

您需要检查表单的Visible属性,即布尔值。
如果是真的,则显示窗体,否则隐藏它。

这只是执行我拥有的窗体。与它们是否为对话框窗体无关。 也就是说,它将采用标准形式

另外,如果您希望它按预期工作,那么应该在传递所有者的地方使用重载

m.ShowDialog(Me)


不是我做过的事,但如果我的主人不是我。OwnedForms我想要回我的钱。

你要找的是房产

检查表单的模态属性是否为true(这意味着表单是通过ShowDialog显示的)

现在,对于您的错误(我现在还没有visual studio尝试),但您的IsAnyDialogShowed()似乎总是返回true:

For Each f As Form In Me.OwnedForms ' (So f belongs to Me)
   If f.Owner Is Me Then 'f.Owner is always me because you are seaching in forms that have as owner the Me form
     Return True
   End If
Next
希望我能帮点忙。 告诉我我能不能再做点什么

所以在您的评论之后。
试试这个:

        For Each frm as Form In Application.OpenForms
            If frm.Modal=True Then
            'do something 
            'Actually you should have only one form because only one can be in modal state
            end if
        Next

再读一遍这个问题,伙计。与可视性无关。我想知道我的应用程序中是否显示了任何对话框,而不仅仅是“我”。但我没有找到类似“app.forms中的每个f as表单”
        For Each frm as Form In Application.OpenForms
            If frm.Modal=True Then
            'do something 
            'Actually you should have only one form because only one can be in modal state
            end if
        Next