I have Windows Application form I need to hide Form
on form_Load
event and it should be hidden from task bar and also from task switcher (i.e. when I press Alt + Tab). means it would not be showing anywhere .
Asked
Active
Viewed 738 times
-1

vyas karnav kumar
- 73
- 6
-
1if you don't want the user to interact with it, why not just create a console application instead of a windows form? – user1666620 Jan 13 '16 at 10:24
-
2Possible duplicate of [Hiding forms on startup: why doesn't this.Hide() hide my form?](http://stackoverflow.com/questions/3769337/hiding-forms-on-startup-why-doesnt-this-hide-hide-my-form) – user1666620 Jan 13 '16 at 10:26
1 Answers
0
So you should try this:
public void Form1_Load(object sender, EventArgs e)
{
ShowInTaskbar = false;
Hide();
}
ShowInTaskbar
indicates wether your Form
should appear in the task bar.
To hide it from Alt+Tab I found this solution on StackOverflow:
protected override CreateParams CreateParams
{
get
{
var Params = base.CreateParams;
Params.ExStyle |= 0x80;
return Params;
}
}
Simply overwrite the CreateParams
property of your Form
as shown above.
UPDATE The order of events when opening a Form
leads to the problem that your visibility is restored after the Load
event. So you will need to overwrite something like this:
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
// if you still want to hide
Hide();
}
-
-
@vyaskarnavkumar So @user1666620 was right. Your solution lies in this answer: http://stackoverflow.com/a/8549250/5528593 Some framework code tries to keep you `Visible`, so with this overridden `OnVisibleChanged` the above code will work. – René Vogt Jan 13 '16 at 10:58