I have an application that can display a window using a form. The form is displayed only if the application is launched using the -debug flag, otherwise it is displayed only in the tray.
var form = new Form(); if(DebugMode) form.Show();
The application launches CloseMainWindow () when launched in debug mode, when the form is displayed. How can I make the application also listen to CloseMainWindow () without showing it? I do not want the user to be able to interact with the form, if not in debug mode.
I tried several approaches, for example, displaying a window, but setting the size to 0. This shows a small form, that is, not hidden.
if (!DebugMode) { form.Show(); form.Size = new Size(0, 0); }
It is also shown, and then hiding it does not work:
if (!DebugMode) { form.Show(); form.Hide(); }
Show it, but it is minimized and not shown on the taskbar, it does not work:
if (!DebugMode) { form.Show(); form.WindowState = FormWindowState.Minimized; form.ShowInTaskbar = false; }
Am I missing something really obvious here, or is it impossible to close processes minimized to the tray in an elegant way?
source share