Control.Show 方法

定义

向用户显示控件。

C#
public void Show ();

示例

下面的代码示例显示一个关于对话框,并暂时在其表面上绘制蓝色方块。 此示例要求你定义了派生自 Form 命名 AboutDialog的类。

C#
private void menuItemHelpAbout_Click(object sender, EventArgs e)
{
   // Create and display a modless about dialog box.
   AboutDialog about = new AboutDialog();
   about.Show();

   // Draw a blue square on the form.
   /* NOTE: This is not a persistent object, it will no longer be
      * visible after the next call to OnPaint. To make it persistent, 
      * override the OnPaint method and draw the square there */
   Graphics g = about.CreateGraphics();
   g.FillRectangle(Brushes.Blue, 10, 10, 50, 50);
}

注解

显示控件等效于将 Visible 属性设置为 true. Show调用该方法后,该Visible属性将返回一个值,true直到Hide调用该方法。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅