views:

53

answers:

4

I was wondering about the difference between using a Control’s Hide() method compared to setting the Visible property to false.

When would I want to use the one over the other?

+2  A: 

They are equivalent. From the documentation for Control.Hide:

Hiding the control is equivalent to setting the Visible property to false.

You can confirm this with reflector:

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

You might use Show() or Hide() when you know the value and use Visible when you take the visibility in as a parameter, although personally I would always use Visible.

Quartermeister
A: 

PictureBox inherits Hide() and Visible from Control. Hide() only sets Visible to false and looks like this:

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

I recommend you using .NET Reflector

prostynick
use .NET Reflector for what?
Amr ElGarhy
I think he means to decompile and in this case see that they are the same.
Brendan Enrick
no need to decompile in this case as it's obvious in the msdn http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx
Amr ElGarhy
@Amr ElGarhy use it if you will have similar questions in the future.
prostynick
A: 

It is really more about your preference here. The two methods will achieve the same result in the same way.

I prefer calling methods, which say what they're doing to change the state of objects. Some people prefer setting the properties of an object.

Brendan Enrick
A: 

Use whatever you like, Hide() or Visible, but i can't find any reason to use one of them except if you are trying to check the control status, so you should say if(pic.Visible) and in this case you can't use the method Hide() you should use the property Visible

Amr ElGarhy