• 0

[C#] this.Hide() not working in Load event


Question

This one's irritating me like a bad rash on a hot day!

I'm developing a utility at the minute for my team that basically speeds up productivity. The form has loads of buttons that perform different functions, and the form can be hidden and all the same functionality is provided from the system tray.

Now i've added an option for the user to run the program from the system tray as soon as it starts (without having to manually minimize it), but I can't get it to do what it says, and it's making a mockery of the checkbox!

I've basically got a check in form_load that says if this property is true, hide the form and show the system tray Icon, but although the system tray Icon shows, the form never gets hidden. I'm assuming that this is because the form is shown at the end of the form load function, and therefore is overriding my code to hide it.

I've tried all sorts of workarounds to fix this, such as creating custom events, all to no avail.

Does anyone have any ideas what I can do to make my form hidden as soon as it loads?

Link to comment
https://www.neowin.net/forum/topic/618404-c-thishide-not-working-in-load-event/
Share on other sites

3 answers to this question

Recommended Posts

  • 0
  El Sid said:
This one's irritating me like a bad rash on a hot day!

I'm developing a utility at the minute for my team that basically speeds up productivity. The form has loads of buttons that perform different functions, and the form can be hidden and all the same functionality is provided from the system tray.

Now i've added an option for the user to run the program from the system tray as soon as it starts (without having to manually minimize it), but I can't get it to do what it says, and it's making a mockery of the checkbox!

I've basically got a check in form_load that says if this property is true, hide the form and show the system tray Icon, but although the system tray Icon shows, the form never gets hidden. I'm assuming that this is because the form is shown at the end of the form load function, and therefore is overriding my code to hide it.

I've tried all sorts of workarounds to fix this, such as creating custom events, all to no avail.

Does anyone have any ideas what I can do to make my form hidden as soon as it loads?

The only reliable way I've found is to set the WindowState equal to Minimize, set ShowInTaskbar to false, and set Visible to false. To show it again, WindowState to Normal, ShowInTaskbar to true, and Visible to true.

  • 0

Have you tried putting your code in the Form_Shown event handler?

If you really don't want anything to flash on the screen, you can try the default Minimized state or set the Location property to Manual and then give it a point off-screen. Then after you hide it, move it back where you want it to show up later. This is assuming you want the window to be shown in the first place, which is necessary to get its window handle created and such.

  • 0

For some reason I must have subconsciously overlooked the Shown event. That does what I need, although I don't really want it to show at all, but it's a minor inconvenience. Cheers guys!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.