Share via


如何:使控件在运行时不可见

有时,你可能想要创建一个在运行时不可见的用户控件。 例如,一个除了警报响起时、其他时间不可见的闹钟控件。 只需要设置 Visible 属性即可轻松实现。 如果 Visible 属性是 true,则控件将正常显示。 如果为 false,则将隐藏控件。 尽管控件中的代码仍然可以在不可见的情况下运行,但将无法通过用户界面与控件进行交互。 如果要创建仍可响应用户输入(例如,单击鼠标)的不可见控件,则应创建透明控件。 有关详细信息,请参阅使控件拥有透明背景

使控件在运行时不可见

  1. Visible 属性设置为 false

    ' To set the Visible property from within your object's own code.  
    Me.Visible = False  
    ' To set the Visible property from another object.  
    myControl1.Visible = False  
    
    // To set the Visible property from within your object's own code.  
    this.Visible = false;  
    // To set the Visible property from another object.  
    myControl1.Visible = false;  
    

另请参阅