public static WatiN_IE window(Form_Control control) { var webBrowser = control.add_Control <System.Windows.Forms.WebBrowser>(); var ie = new WatiN_IE(webBrowser); ie.HostControl = control; ie.setWebBrowserObject(webBrowser); var parentForm = control.parentForm(); if (parentForm.notNull()) { parentForm.Closed += (sender, e) => { "Parent form closed to detaching and close WatiN_IE".info(); ie.detach(); ie.close(); }; } return(ie); }