通过名称找到控件(VB.NET)

1、通过For Each Control in Controls方法查看;
2、通过Reflection查看,代码如下:
Public Function GetControlByName(ByVal Name As String) As Control

        
'now, why would I put a "_" in front of the name? 
        Dim info As System.Reflection.FieldInfo = Me.GetType().GetField("_" & Name, _
        System.Reflection.BindingFlags.NonPublic Or _
        System.Reflection.BindingFlags.Instance Or _
        System.Reflection.BindingFlags.Public Or _
        System.Reflection.BindingFlags.IgnoreCase)

        If info Is Nothing Then Return Nothing
        Dim o As Object 
= info.GetValue(Me)
        Return o

    End Function
原文地址:https://www.cnblogs.com/zqfleaf/p/560865.html