private void notifyIconSysTray_MouseClick(object sender, MouseEventArgs e) { // Show system tray menu if no modal dialog is open. if (e.Button == System.Windows.Forms.MouseButtons.Right && bModalOpen == false) { Win32.SetForegroundWindow(new HandleRef(this, this.Handle)); Win32.TrackPopupMenuEx(mnuNotify.Handle, 0x0, Cursor.Position.X, Cursor.Position.Y, this.Handle, (IntPtr)null); } }
/// <summary> /// Restores the window to its normal state. /// </summary> /// <param name="bRestore">If true, restores window to previous state, else window is minimized.</param> public virtual void ShowWindow(bool bRestore, bool bActivated) { // If window is already visible, just set it to foreground. if (this.Visible && this.WindowState != FormWindowState.Minimized) { // If form was activated by user action, bring it to foreground. if (bActivated) { Win32.SetForegroundWindow(new System.Runtime.InteropServices.HandleRef(this, this.Handle)); } else { // Form was shown programatically, no need to bring to foreground if already visible. IntPtr mainHwnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; if (mainHwnd != this.Handle) { FlashWindow(); } } return; } this.Show(); this.ShowInTaskbar = true; if (bRestore) { // Restore window to its previous state. this.WindowState = prevWindowState; Win32.SetForegroundWindow(new System.Runtime.InteropServices.HandleRef(this, this.Handle)); } else { // Minimize the window, but flash it to alert the user. this.WindowState = FormWindowState.Minimized; FlashWindow(); } }
public void HistoryViewer_SetForeground(object sender, EventArgs e) { this.WindowState = prevWindowState; Win32.SetForegroundWindow(new HandleRef(this, this.Handle)); }
/// <summary> /// Bring the window to the foreground. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void FileTransferDialog_SetForeground(object sender, EventArgs e) { this.WindowState = prevWindowState; Win32.SetForegroundWindow(new HandleRef(this, this.Handle)); }