简体   繁体   中英

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?

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.

使用你喜欢的任何东西, Hide()Visible ,但我找不到任何理由更喜欢其中一个,除非你试图检查控制可见性状态,所以你应该说if(pic.Visible)和在这种情况下你不能使用方法Hide()你应该使用属性Visible

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM