Tuesday, May 25, 2010

Show Application Not as a Task but as a Process

To tell the operating system to not show an application as a Task in the task manager but as a process, it suffices to "hide" the application literally.
Let us consider a Windows-Forms application as example. If we change the property Visible of the form to false, e.g. by
this.Visible = false;
(with this always the current form is meant), the current form becomes invisible and therefor is only listed as a process in the task manager.
While running, e.g. when clicking on a button, this code can be run without problems.
A bit harder is it, if the form is to be hidden directly from start on.
In Form1_Load the code does not affect the behaviour, since after this function the function Show() of the form is called and the form is shown again.
In my opinion the best method to hide the form from start on is to override void OnShown(EventArgs e) of the form, which is called in the call of Show().
The complete declaration of the function is:
protected override void OnShown(EventArgs e)
    this.Visible = false;
base.OnShown(e); is added by the compiler automatically, this line prompts the call of OnShown() of the father class Form.

No comments:

Post a Comment