2010-11-11 4 views
1

Voici mon code que je veux exécuter. Je veux appeler la même fonction que l'utilisateur choisit dans la zone de liste déroulante. S'il vous plaît aviser comment cela peut être géré.Suite à ma question: Appeler des fonctions privées en utilisant combobox

Public Class Form1 
Private Sub One() 
    MsgBox("One is called") 
End Sub 
Private Sub Two() 
    MsgBox("Two is called") 
End Sub 
Private Sub Three() 
    MsgBox("Three is called") 
End Sub 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 
    Dim vrTextNow As String = ComboBox1.Text 
    Call vrTextNow 
End Sub 

End Class

Répondre

1

Vous devrez utiliser la réflexion pour y parvenir. Reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime

Ajouter Imports System.Reflection avant votre définition de classe et utiliser ce code en vous ComboBox1_SelectedIndexChanged méthode

Dim vrTextNow As String = ComboBox1.Text 
     Dim method As MethodInfo 
     method = Me.GetType().GetMethod(vrTextNow, BindingFlags.NonPublic Or BindingFlags.Instance) 
     method.Invoke(Me, Nothing) 
+0

Une grande aide! Merci beaucoup. –

Questions connexes