0

Hi,

I'm trying to create multiple instances of a child form. This form has an event that feeds a string variable back to the parent so I'm declaring it with WithEvents which is declared outside of the Sub - meaning multiple clicks will not open multiple forms.

Any idea on another method of doing this while keeping the event?:

Dim WithEvents FRestoreDB As New FormRestoreDB()

    Private Sub BtnOpenDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpenDB.Click
        If Not IsNothing(FRestoreDB) Then
            If Not FRestoreDB.IsDisposed Then
                FRestoreDB.StartPosition = FormStartPosition.Manual
                FRestoreDB.Show()
            Else
                FRestoreDB = New FormRestoreDB()
                FRestoreDB.Show()
            End If
        Else
            FRestoreDB = New FormRestoreDB()
            FRestoreDB.Show()
        End If

    End Sub
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by madlan
1

You can try something like

Dim WithEvents Frm As FormRestoreDB
	Dim OpenForms As FormRestoreDB()

	Private Sub BtnOpenDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpenDB.Click
		'
		'	Create a new instance
		'
		Frm = New FormRestoreDB
		'
		'	Add to the forms collection (if you need it). 
		'
		If OpenForms Is Nothing Then
			ReDim OpenForms(0)
		Else
			ReDim OpenForms(OpenForms.Length)
		End If
		OpenForms(OpenForms.Length - 1) = Frm
		'
		'	Show the form
		'
		Frm.show()
	End Sub

When you create a new instance, the fired event of each instance will go to the same parent handler.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.