VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • 通过名称找到控件(VB.NET)

1、通过For Each Control in Controls方法查看;
2、通过Reflection查看,代码如下:

None.gif Public Function GetControlByName(ByVal Name As String) As Control
None.gif
None.gif         ' now, why would I put a "_" in front of the name? 
None.gif         Dim info As System.Reflection.FieldInfo  =  Me.GetType().GetField( " _ "   &  Name, _
None.gif        System.Reflection.BindingFlags.NonPublic Or _
None.gif        System.Reflection.BindingFlags.Instance Or _
None.gif        System.Reflection.BindingFlags.Public Or _
None.gif        System.Reflection.BindingFlags.IgnoreCase)
None.gif
None.gif        If info Is Nothing Then Return Nothing
None.gif        Dim o As Object  =  info.GetValue(Me)
None.gif        Return o
None.gif
None.gif    End Function

转载于:https://www.cnblogs.com/zqfleaf/archive/2006/11/15/560865.html


相关教程