-2

I can use the Hide() to hide form in a win app. but also I could use Visible = false to hide a form. if I use either way to show the hidden form I have to use Visible = true.

  1. So which one should I use to hide the form, Hide() or Visible = false? and why?
  2. What happens when I use Hide() to hide form?
  3. what happens if I use Close() to hide a form?
Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
sniff_bits
  • 389
  • 2
  • 7
  • 17
  • It's often a good idea to look at those methods from the inside to see what makes them work when a question such as this pops up. – B.K. Feb 11 '14 at 05:01

2 Answers2

8

There is no difference.

Form inherits from Control. Control.Hide is implemented like this:

public void Hide()
{
    this.Visible = false;
}

When you hide a form, you can show is using Show:

yourForm.Show();

..which is implemented as:

public void Show()
{
    this.Visible = true;
}

So it is personal preference. Just make sure you use them in pairs so it's nicer to read:

form.Hide();
form.Show();

..as opposed to..

form.Hide();
form.Visible = true;

When using Close.. you aren't hiding the form. You are literally sending a WM_CLOSE to the window.. removing it. Dispose is also called.

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
0
  1. If it's specifically your intention to hide the form then call Hide to make that clear. If it's your intention to change the visibility of the form and the same code might do either then set Visible.

  2. It disappears from view. Presumably you wanted more than that but it's not clear what that is from your question.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46