Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control difference between Hide() and Visible?

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?

like image 301
erikric Avatar asked Aug 30 '10 12:08

erikric


People also ask

What does Visible false mean?

When you set Visible = false to a control, it is not rendered. That means there is no HTML representation of that control sent to the page.

What is visible in VB net?

Description. The Visible property lets you determine or set whether the form is visible on screen. To display the form on screen, set the Visible property to True or use the Show or ShowModal method. To hide the form, set Visible to False or use the Hide method.

Is a control property that hides the object?

To hide an object when printing, use the DisplayWhen property. You can use the Visible property to hide a control on a form or report by including the property in a macro or event procedure that runs when the Current event occurs.


2 Answers

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.

like image 81
Quartermeister Avatar answered Sep 24 '22 11:09

Quartermeister


Use whatever you like, Hide() or Visible, but I can't find any reason to prefer one of them except if you are trying to check the control visibility 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

like image 32
Amr Elgarhy Avatar answered Sep 24 '22 11:09

Amr Elgarhy