日期:2014-05-18 浏览次数:21013 次
private void ShowContextMenu() { if ((this.contextMenu != null) || (this.contextMenuStrip != null)) { NativeMethods.POINT pt = new NativeMethods.POINT(); UnsafeNativeMethods.GetCursorPos(pt); UnsafeNativeMethods.SetForegroundWindow(new HandleRef(this.window, this.window.Handle)); if (this.contextMenu != null) { this.contextMenu.OnPopup(EventArgs.Empty); SafeNativeMethods.TrackPopupMenuEx(new HandleRef(this.contextMenu, this.contextMenu.Handle), 0x48, pt.x, pt.y, new HandleRef(this.window, this.window.Handle), null); UnsafeNativeMethods.PostMessage(new HandleRef(this.window, this.window.Handle), 0, IntPtr.Zero, IntPtr.Zero); } else if (this.contextMenuStrip != null) { this.contextMenuStrip.ShowInTaskbar(pt.x, pt.y); } } }