GetType().InvokeMember

程式執行階段,要如何判斷表單中是否存在 tooltip 這篇文章中,提問者問到要如何判斷Form裡面是不是有ToolTip,而ToolTip不包含在Controls集合中,測試了一下,不太確定這樣的做法是不是繞了遠路,大家研究看看吧
Imports System.ComponentModel

Public Class Form1

Private Function HasToolTip() As Boolean
If Me.components.Components Is Nothing Then
Return False
Else
For Each c As Component In Me.components.Components
If TypeName(c) = "ToolTip" Then
Return True
End If
Next
Return False
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Me.HasToolTip())
Test.CheckToolTip(Me)
End Sub
End Class

Public Class Test
Public Shared Sub CheckToolTip(ByRef frm As Object)
Dim o As Object = _
frm.GetType().InvokeMember("HasToolTip", _
Reflection.BindingFlags.Instance Or _
Reflection.BindingFlags.InvokeMethod Or _
Reflection.BindingFlags.Public Or _
Reflection.BindingFlags.NonPublic, Nothing, frm, Nothing)
MessageBox.Show(o.ToString)
End Sub
End Class

留言

這個網誌中的熱門文章

開啟cshtml檔案時,出現『並未將物件參考設定為物件執行個體』的錯誤訊息

無法設定中斷點 尚未載入符號檔

DataGridView欄位計算總合