zqfleaf

通过名称找到控件(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

posted on 2006-11-15 11:51  Hunter II  阅读(586)  评论(0编辑  收藏  举报

导航