請問如何取得程式產生的FORM

P陳
1.用程式產生 4個 NBSform,繼承 BSFORM ,BSFORM中有一個BUTTON 放 Me.DialogResult = DialogResult.OK
2.請問主程式中要如何找到其中一個 BSForm2
3.如果有加上 Nbsform.Show() 第一次可以找到,但ShowDialog後,按下 button1 後,被關掉後就找不到了

4.請問各位 讓如何讓 bsform2 可以一直被 ShowDialog


Private Sub CreateBS_Click(sender As Object, e As EventArgs) Handles CreateBS.Click
        For ii = 1 To 4
            Dim Nbsform As New BsForm
            'Dim Button1 As New Button
            Nbsform.Text = "Bsform" & ii
            Nbsform.Name = "Bsform" & ii
            'Nbsform.Show()
            'Nbsform.Hide()

        Next
    End Sub

    Private Sub FindBsform2_Click(sender As Object, e As EventArgs) Handles FindBsform2.Click
        Dim form1 As Form, FindBs As New Form
        FindBs = Nothing
        For Each form1 In Application.OpenForms
            If form1.Name = "Bsform2" Then
                FindBs = form1
                Exit For
            End If
        Next
        FindBs.ShowDialog()
    End Sub





Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.DialogResult = DialogResult.OK
    End Sub

最有價值解答

香帥
Public Class Form1
    Dim Nbsform(0) As BsForm
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        For ii = 1 To 4
            ReDim Preserve Nbsform(ii - 1)

            Nbsform(ii - 1) = New BsForm

            Nbsform(ii - 1).Text = "Bsform" & ii
            Nbsform(ii - 1).Name = "Bsform" & ii


        Next
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim form1 As Form, FindBs As New Form
        FindBs = Nothing
        For Each form1 In Nbsform

            If form1.Name = "Bsform2" Then
                FindBs = form1
                Exit For
            End If
        Next
        FindBs.ShowDialog()
    End Sub
End Class

香帥
補充一下,您原來的Application.OpenForms 測試後真的要form有打開才找得到,因此建議改用2樓方式。
P陳
香帥您好:
謝謝您,這樣可以了
回到頂部