Need IntPtr for a Form (VB.Net)
Question
I need the intPtr for a form. Control.FromHandle(control) gives me the control from a handle, but I need the opposite--get the handle from a control. How do I do this?
Solution
Try
Dim handle As IntPtr = someControl.Handle
Note: This will only work after the Handle for the control is created. There is a window of time in between when you create a control and when it is rendered to some degree where this may return IntPtr.Zero
OTHER TIPS
Note: This will only work after the Handle for the control is created. There is a window of time in between when you create a control and when it is rendered to some degree where this may return IntPtr.Zero
I have to disagree with JaredPar on this : the get accessor of the Handle property calls CreateHandle if the handle is not yet created (you can check with Reflector). It's important to be aware of that because in some cases it could have unexpected consequences