2011-07-17 6 views
1

두 번 이상 양식을 열 수 있습니까?두 번 이상 같은 양식 열기

를 눌러 단추 1 Form2를 다시

보도 Button1을 열어 form2.show

단추 1 가 다른 Form2를 옆에 오래된 Form2를

가능한 경우에 열어, Form1에 버튼을 모두 죽일 수있다 Form2 창이 열리나요?

답변

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 
+0

개체 참조가 개체의 인스턴스로 설정되지 않았습니다. m_WindowList.Add (NewWindow) 해당 줄의 문제 – SirAudens

+0

아, 죄송합니다. m_WindowList 선언에 새로 추가하십시오. 위의 대답에서 해결했습니다. –

+0

달콤한. 너 대단해! – SirAudens

1
Dim MyNewForm2 = New Form2 
MyNewForm2.Show 
+0

.... 이제 나는 바보 같은 ... 그 간단한 ... 감사합니다! 그냥 호기심에서 벗어난 – SirAudens

+0

. 하나의 button1을 텍스트 상자의 숫자와 같이 많은 창문이 어떻게 열리는 지 열어 볼 수있는 방법이 있습니까? 그리고 모든 form2를 닫아서 그곳에서 작동하는 것을 무력화 할 수 있습니까? – SirAudens

+0

@SirAudens, 그것을 달성하는 몇 가지 방법이 있습니다. 하나의 간단한 방법은 로컬 배열의 모든 새 창에 대한 참조를 유지 한 다음 두 번째 버튼을 클릭하여 닫기/모두 삭제를 클릭하는 것입니다. – Shimmy

관련 문제