0

I use the following code to restore a WinForms app from the system tray:

this.WindowState = FormWindowState.Normal;
this.Show();
this.BringToFront();

I need to set the focus on a textbox when the window is shown. I do this in the OnActivated override and this works fine in general except when restoring from the tray with the code above. Debugging shows that OnActivated is not being called.

Any suggestions?

Thank you all.

fujiFX
  • 413
  • 9
  • 18
  • Have you tried `shown` event of the form? As @BugFinder suggested, you might as well add the line to set focus to the textbox along with the code used to restore the `WinForms` app – fujiFX May 02 '16 at 23:21
  • I think `Shown` only works the first time the form is shown. I also tried `this.Activate()` but `OnActivated` does not get called. So the question is, how/when/why does `OnActivated` get called? –  May 03 '16 at 00:07
  • 1
    How do you minimize the application to system tray? – Reza Aghaei May 03 '16 at 10:45
  • Where do you write such code? Can you share the code? – Reza Aghaei May 04 '16 at 18:21
  • Which code? Hiding the window can be done anywhere. Restoring it happens on response to a click on the system tray icon's menu. The problem comes down to why `OnActivated` is not called by the code that I posted in the question. It is a bit of a puzzle because `OnActivated` is called normally otherwise. –  May 04 '16 at 23:02

0 Answers0