Difference between revisions of "How to get tooltip handle in NET"

From HashVB
Jump to: navigation, search
 
m (Tidied code sample)
Line 1: Line 1:
 
{{VB.NET}}
 
{{VB.NET}}
                                  How to get Tooltip handle in .NET
 
 
 
.NET ToolTip control doesn't expose Handle property.  
 
.NET ToolTip control doesn't expose Handle property.  
 
Then we should use InvokeMember to retrieve that property
 
Then we should use InvokeMember to retrieve that property
Line 7: Line 5:
 
The following function returns the handle:
 
The following function returns the handle:
  
Public Shared Function GetToolTipHandle(ByVal ctrlToolTip As ToolTip) As IntPtr
+
Public Shared Function GetToolTipHandle(ByVal ctrlToolTip As ToolTip) As IntPtr
 
+
 
         Dim obj As Object
 
         Dim obj As Object
 
         Dim hwnd As IntPtr
 
         Dim hwnd As IntPtr
Line 16: Line 14:
 
             hwnd = CType(obj, IntPtr)
 
             hwnd = CType(obj, IntPtr)
 
         Catch ex As Exception
 
         Catch ex As Exception
 
+
 
         End Try
 
         End Try
 
         Return hwnd
 
         Return hwnd
 +
 +
End Function
  
End Function
+
How to use the function in your program:
  
 +
Dim hwnd as IntPtr = GetToolTipHandle(ToolTip1)
  
How to use the function in your program:
+
To convert the pointer to numeric(integer) use like this:
 
+
Dim hwnd as IntPtr = GetToolTipHandle(ToolTip1)
+
  
To convert the pointer to numeric(integer) use like this: hwnd.toInt32()
+
hwnd.toInt32()

Revision as of 14:56, 26 January 2006

float
 This article is based on Visual Basic.NET. Find other Visual Basic.NET articles.

.NET ToolTip control doesn't expose Handle property. Then we should use InvokeMember to retrieve that property

The following function returns the handle:

Public Shared Function GetToolTipHandle(ByVal ctrlToolTip As ToolTip) As IntPtr

       Dim obj As Object
       Dim hwnd As IntPtr
       Try
           hwnd = IntPtr.Zero
           obj = GetType(ToolTip).InvokeMember("Handle", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetProperty, Nothing, ctrlToolTip, Nothing)
           hwnd = CType(obj, IntPtr)
       Catch ex As Exception

       End Try
       Return hwnd

End Function

How to use the function in your program:

Dim hwnd as IntPtr = GetToolTipHandle(ToolTip1)

To convert the pointer to numeric(integer) use like this:

hwnd.toInt32()