Aprire form in VB.NET

  • Creatore Discussione Creatore Discussione mythar
  • Data di inizio Data di inizio

mythar

Utente Attivo
16 Gen 2006
148
0
0
46
Naples
Ho una subroutine di questo tipo:

Private Sub ApriForm(strNomeForm as String)
dim frm as New frmFormDaAprire
If strNomeForm <> "" Then
'Qui devo aprire il form
End If
End Sub

dove al posto del commento devo inserire il codice per aprire un form.

Normalmente dovrei usare una Select Case e se trovo una corrispondenza apro il form.

Però io vorrei aprire il form con una riga tipo:
frm(strNomeForm).show()

E' possibile farlo?

Aspetto notizie e nel frattempo continuo a studiare VB.NET
:book: :book: :book: :book: :book:
 
Ho trovato la soluzione girando sul WEB, ve la posto

Function GetFormByName(ByVal FormName As String) As Form
'first try: in case the full namespace has been provided (as it should )
Dim T As Type = Type.GetType(FormName, False)
'if not found prepend default namespace
If T Is Nothing Then
Dim Fullname As String = Application.ProductName & "." & FormName
T = Type.GetType(Fullname, True, True)
End If
Return CType(Activator.CreateInstance(T), Form)
End Function

Spero di essere stato utile.

:beer:
 

Discussioni simili