Ciao a tutti, sto cercando di creare una classe per gestire l'apertura e la chiusura delle varie maschere (form). L'obiettivo è quello di aprire i vari forms e se il form richiamato risulta aperto, portarlo in primo piano. Per fare questo ho iniziato con un approccio di questo genere:
Anche se il tutto funziona bene, non sono sicuro sia la strada giusta...soprattutto per il fatto che devo dichiarare tante variabili quanti sono i forms.codice:Public Class clsForm Private Shared WithEvents _f2 As Form2 Private Shared WithEvents _f3 As Form3 Public Enum eForm eForm2 eForm3 End Enum Public Sub ApriForm(ByVal tipo As eForm, ByVal frmCaller As Form) Select Case tipo Case eForm.eForm2 If _f2 Is Nothing Then _f2 = New Form2(frmCaller) _f2.Show() Else _f2.Select() End If Case eForm.eForm3 If _f3 Is Nothing Then _f3 = New Form3(frmCaller) _f3.Show() Else _f3.Select() End If End Select End Sub Public Function ChiudiForms() As Boolean Dim retVal As Boolean = True If Not _f2 Is Nothing Then If MessageBox.Show(String.Format("Il form {0} è aperto." & Environment.NewLine & "Vuoi chiuderlo?", _f2.Name), "Chiusura applicazione", MessageBoxButtons.YesNo) = DialogResult.Yes Then _f2.Dispose() _f2 = Nothing Else _f2.Select() retVal = False End If End If If retVal Then If Not _f3 Is Nothing Then If MessageBox.Show(String.Format("Il form {0} è aperto." & Environment.NewLine & "Vuoi chiuderlo?", _f3.Name), "Chiusura applicazione", MessageBoxButtons.YesNo) = DialogResult.Yes Then _f3.Dispose() _f3 = Nothing Else _f3.Select() retVal = False End If End If End If Return retVal End Function Private Shared Sub _f2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles _f2.FormClosed _f2.Dispose() _f2 = Nothing End Sub Private Shared Sub _f3_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles _f3.FormClosed _f3.Dispose() _f3 = Nothing End Sub End Class
Consigli/opinioni in merito?
Grazie

Rispondi quotando