/// <summary> /// A thread safe version to receive the <see cref="Control.Handle"/> /// property of the control. /// </summary> /// <param name="control">The <see cref="Control"/> to retreive the handle for.</param> /// <returns>An <see cref="IntPtr"/> with the handle of the control.</returns> public static IntPtr GetHandle(Control control) { if (control.InvokeRequired) { var d = new GetHandleCallback(GetHandle); return (IntPtr)control.Invoke(d, control); } return control.Handle; }
/// <summary> /// A thread safe version to receive the <see cref="Control.Handle"/> /// property of the control. /// </summary> /// <param name="control">The <see cref="Control"/> to retreive the handle for.</param> /// <returns>An <see cref="IntPtr"/> with the handle of the control.</returns> public static IntPtr GetHandle(Control control) { if (control.InvokeRequired) { var d = new GetHandleCallback(GetHandle); return((IntPtr)control.Invoke(d, control)); } return(control.Handle); }
public IntPtr GetHandle() { if (InvokeRequired) { // 解决窗体关闭时出现“访问已释放句柄”的异常 while (!IsHandleCreated) { if (Disposing || IsDisposed) { return(IntPtr.Zero); } } GetHandleCallback d = new GetHandleCallback(GetHandle); return((IntPtr)Invoke(d, null)); } else { return(Handle); } }