Check if form is Opened

前端 未结 8 1373
陌清茗
陌清茗 2020-12-30 23:56

I give this question for more knowledge. How can I know if the form is Opened in my application or not, in order not to open it again I mean not to create an instance of the

8条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 00:30

    you can try this

    Dim formText As String
    Dim prevText As String
    
     Private Sub OpenForm(ByVal frm As Windows.Forms.Form)
            formText = frm.Text
            If formText = prevText Then Exit Sub
            CloseForms()
            ' Make it a child of this MDI form before showing it.
            frm.MdiParent = Me
            frm.Show()
            frm.Location = New Point(0, 0)
            prevText = formText
        End Sub
    
        Private Sub CloseForms()
            For Each ChildForm As Form In Me.MdiChildren
                ChildForm.Close()
            Next
        End Sub
    
        Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PayablesToolStripMenuItem.Click
                OpenForm(frmPayables)
            End Sub
    

提交回复
热议问题