Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 关于我的问题:使用combobox调用私有函数_Vb.net - Fatal编程技术网

Vb.net 关于我的问题:使用combobox调用私有函数

Vb.net 关于我的问题:使用combobox调用私有函数,vb.net,Vb.net,下面是我想要运行的代码。我想调用用户从组合框中选择的相同函数。请告知如何进行管理 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_S

下面是我想要运行的代码。我想调用用户从组合框中选择的相同函数。请告知如何进行管理

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

最终类

您需要使用反射来实现这一点

在类定义之前添加
Imports System.Reflection
,并在组合框1\u SelectedIndexChanged方法中使用此代码

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

您需要使用反射来实现这一点

在类定义之前添加
Imports System.Reflection
,并在组合框1\u SelectedIndexChanged方法中使用此代码

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