Reputation: 13025
I'm new to C# but working on a very large C# project. I am not the original author of any source code of the project. I have a form which I'm trying to hide after a button is pressed on the form. I tried both of the following:
this.Hide();
this.Visible = false;
Neither makes the form hide. I'm wondering what makes a form not to be hidden.
I'm using .NET Framework 3.5 and VS 2008 on Windows XP SP 3.
Upvotes: 2
Views: 134
Reputation: 65
this
reference to the current instance. For example, if you're in the ButtonClick event function of MainForm then this.Close() will close the MainForm. If you want to close another form, you should reference it such as instantiating it
SecondForm secondForm = new SeondForm();
form.Close();
Upvotes: 1
Reputation: 47490
Both below ways should work. Not sure why you say this.Hide() not working. Make sure 'this' is the actual form that you want to hide.
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.Visible = false;
or
this.Hide();
Upvotes: 1
Reputation: 11844
Have a try with this code
WindowState = FormWindowState.Minimized;
Hide();
Upvotes: 1