0

I would like to reproduce the "on focus" behavior when you minimize an application on a context menu strip (I need that in C#), let me explain why:

When you minimize a window, the focus will be restored to the previous application that was used last, it's what I want to reproduce, basically, when I press on a selection on the context menu strip, I would like that application that was previously focused get the focus back so I don't have to click on it again.

Is there any way to achieve that?

I tried to play This.WindowState = this.WindowState = FormWindowState.Minimized; to make the program think it's getting minimized but it did not recreate the behavior I am expecting.

Thanks a lot for your time and help.

P.S.: The context menu strip is when you right click on an icon in the system tray (bottom right of the screen), basically the right click on the notify icon.

Context menu strip is the name of the control in VS2013.

The menus in the context menu strip are called "toolstrip menu items".

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Dyr Fenrir
  • 129
  • 2
  • 15
  • Erm, you want the user to set the focus on your context menu in order to set the focus to another app? Hard to make sense of that, he'll just click the taskbar button of the app instead. Anyhoo, you'll have to do the same thing the Windows window manager does, keeping track of what window has the foreground. Not easy to do in C#, pinvoke required to use SetWinEventHook and SetForegroundWindow. – Hans Passant Sep 28 '14 at 18:39
  • Basically, I just want the use to right click on the notify icon, press on a button there (to start a timer) and that the application that was used last get the focus back, like if the user would open an application, start the timer with a button and then minimize it afterward. I just want to save the need to open the application, press on the button, then minimize. For the user, it was easier to just use a notify icon, but that way the window that was used last does not get the focus back once the start timer button is pressed. – Dyr Fenrir Sep 28 '14 at 18:57

0 Answers0