不止一次打开同一个表格

时间:2011-07-17 05:28:11

标签: vb.net winforms

是否可以多次打开表单?

button1的 form2.show

按下按钮1 form2打开

再次按下按钮1 另一个form2在旧form2旁边打开

如果可能,Form1上的按钮是否可以杀死所有Form2窗口?

2 个答案:

答案 0 :(得分:2)

当然有可能。只需将两个相同形式的实例调暗。

Public Class Form1

    Private m_WindowList As New List(Of Form2)

    Private Sub OpenWindowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenWindowButton.Click
        OpenWindow()
    End Sub

    Private Sub CloseWindowsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseWindowsButton.Click
        CloseWindows()
    End Sub

    Private Sub OpenWindowsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenWindowsButton.Click
        Dim WindowCount As Int32
        If Int32.TryParse(WindowCountTextBox.Text, WindowCount) Then
            OpenWindows(WindowCount)
        End If
    End Sub

    Private Sub OpenWindow()
        Dim NewWindow As New Form2
        m_WindowList.Add(NewWindow)
        NewWindow.Show()
    End Sub

    Private Sub OpenWindows(ByVal Count As Int32)
        For i = 1 To Count
            OpenWindow()
        Next
    End Sub

    Private Sub CloseWindows()
        For Each Window In m_WindowList
            Window.Close()
            Window.Dispose()
        Next
        m_WindowList.Clear()
    End Sub

End Class

答案 1 :(得分:1)

Dim MyNewForm2 = New Form2
MyNewForm2.Show