This is one of those things that’s obvious once you know it.  When dealing with COM, there is often a need to convert a WinForms Form object to an IntPtr handle, and vice versa.

Convert Handle to Form

static public Form GetForm( IntPtr handle )
{
    return handle == IntPtr.Zero ?
        null :
        Control.FromHandle( handle ) as Form;
}

Convert Form to Handle

Form form = new Form();
IntPtr handle = form.Handle;

Share and Enjoy:
  • Digg
  • Twitter
  • Facebook
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Google Bookmarks
  • Slashdot