当我创建另一个正在运行的程序副本时,如何关闭该程序?

时间:2019-03-07 04:21:38

标签: vb.net visual-studio visual-studio-2010

这是代码:

Dim newform As main
        newform = New main()
        newform.Show()
        newform = Nothing

newform.closeMe.Close/Me.Exit/Me.Dispose将关闭相同的表格, 不使用关闭程序将使许多程序运行

enter image description here

1 个答案:

答案 0 :(得分:0)

1。首先,您创建一个MDIParent,一个主窗体,一个模块代码

2。在模块中编写代码

Module MainModule
    Public Forms1 As New List(Of frmMain)()

    Public Sub New1Form()
        Dim form2a = New frmMain
        Forms1.Add(form2a)
        Forms1.Item(Forms1.Count - 1).Text = "Form" & Forms1.Count - 1
        Forms1.Item(Forms1.Count - 1).Show()

    End Sub

    Public Sub NewForm()

        Dim form2a = New frmMain
        Forms1.Add(form2a)

        Dim form2b = New frmMain
        Forms1.Add(form2b)

        Forms1.Item(Forms1.Count - 1).Text = "Form" & Forms1.Count - 1
        Forms1.Item(Forms1.Count - 1).Show()
        Forms1.Item(Forms1.Count - 2).Text = "Form" & Forms1.Count - 2
        Forms1.Item(Forms1.Count - 2).Show()
    End Sub

    Public Sub CloseOldForm()
        If (Forms1.Count - 3) >= 0 Then
            Forms1.Item(Forms1.Count - 3).Close()
        End If
    End Sub
End Module

3。在MDIParent1中编写代码

 Private Sub NewToolStripButton_Click(sender As Object, e As EventArgs) Handles NewToolStripButton.Click
        MainModule.New1Form()
    End Sub

4。以主表单编写代码

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MainModule.NewForm()
        If (MainModule.Forms1.Count - 3) >= 0 Then
            Me.Hide()
        End If
    End Sub

5。下载源代码

https://www.tummosoftware.com/p/how-to-close-existing-running-program.html