Share via


StatusBar.ShowPanels 属性

获取或设置一个值,该值指示是否显示已添加到控件中的任何面板。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property ShowPanels As Boolean
用法
Dim instance As StatusBar
Dim value As Boolean

value = instance.ShowPanels

instance.ShowPanels = value
public bool ShowPanels { get; set; }
public:
property bool ShowPanels {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_ShowPanels ()

/** @property */
public void set_ShowPanels (boolean value)
public function get ShowPanels () : boolean

public function set ShowPanels (value : boolean)

属性值

如果显示面板,则为 true;否则为 false。默认为 false

备注

默认情况下,StatusBar 控件显示其 Text 属性的值而不显示任何面板。当 ShowPanels 设置为 true 时,将显示在 StatusBar 控件中指定的任何 StatusBarPanel 对象。创建 StatusBar 类的实例时,最初并不创建任何面板。可以通过使用 StatusBar.StatusBarPanelCollection 类的 Add 方法向 StatusBar 控件添加面板。此集合类可以通过 StatusBarPanels 属性进行访问。

示例

下面的代码示例在窗体上创建一个 StatusBar 控件,并添加两个 StatusBarPanel 对象。其中一个 StatusBarPanel 对象名为 panel1,它显示应用程序的状态文本。另一个 StatusBarPanel 名为 panel2,它显示当前日期,并使用 StatusBarPanel 类的 ToolTipText 属性显示当前时间。此示例使用 ShowPanels 属性确保显示多个面板而不是一个标准面板,并使用 Panels 属性访问 StatusBar.StatusBarPanelCollectionAdd 方法,以向 StatusBar 中添加面板。该示例还使用 AutoSizeBorderStyleToolTipTextText 属性来初始化 StatusBarPanel 对象。本示例要求示例中定义的方法已定义并且是从 Form 的构造函数中调用的。

Private Sub CreateMyStatusBar()
   ' Create a StatusBar control.
   Dim statusBar1 As New StatusBar()

   ' Create two StatusBarPanel objects to display in the StatusBar.
   Dim panel1 As New StatusBarPanel()
   Dim panel2 As New StatusBarPanel()

   ' Display the first panel with a sunken border style.
   panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken

   ' Initialize the text of the panel.
   panel1.Text = "Ready..."

   ' Set the AutoSize property to use all remaining space on the StatusBar.
   panel1.AutoSize = StatusBarPanelAutoSize.Spring
   
   ' Display the second panel with a raised border style.
   panel2.BorderStyle = StatusBarPanelBorderStyle.Raised
   
   ' Create ToolTip text that displays the time the application was started.
   panel2.ToolTipText = "Started: " & System.DateTime.Now.ToShortTimeString()

   ' Set the text of the panel to the current date.
   panel2.Text = System.DateTime.Today.ToLongDateString()

   ' Set the AutoSize property to size the panel to the size of the contents.
   panel2.AutoSize = StatusBarPanelAutoSize.Contents

   ' Display panels in the StatusBar control.
   statusBar1.ShowPanels = True

   ' Add both panels to the StatusBarPanelCollection of the StatusBar.            
   statusBar1.Panels.Add(panel1)
   statusBar1.Panels.Add(panel2)

   ' Add the StatusBar to the form.
   Me.Controls.Add(statusBar1)
End Sub
private void CreateMyStatusBar()
{
    // Create a StatusBar control.
    StatusBar statusBar1 = new StatusBar();
    // Create two StatusBarPanel objects to display in the StatusBar.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Display the first panel with a sunken border style.
    panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;
    // Initialize the text of the panel.
    panel1.Text = "Ready...";
    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.AutoSize = StatusBarPanelAutoSize.Spring;
    
    // Display the second panel with a raised border style.
    panel2.BorderStyle = StatusBarPanelBorderStyle.Raised;
    
    // Create ToolTip text that displays time the application was 
          //started.
    panel2.ToolTipText = "Started: " + System.DateTime.Now.ToShortTimeString();
    // Set the text of the panel to the current date.
    panel2.Text = System.DateTime.Today.ToLongDateString();
    // Set the AutoSize property to size the panel to the size of the contents.
    panel2.AutoSize = StatusBarPanelAutoSize.Contents;
                
    // Display panels in the StatusBar control.
    statusBar1.ShowPanels = true;

    // Add both panels to the StatusBarPanelCollection of the StatusBar.            
    statusBar1.Panels.Add(panel1);
    statusBar1.Panels.Add(panel2);

    // Add the StatusBar to the form.
    this.Controls.Add(statusBar1);
}
private:
   void CreateMyStatusBar()
   {
      // Create a StatusBar control.
      StatusBar^ statusBar1 = gcnew StatusBar;

      // Create two StatusBarPanel objects to display in the StatusBar.
      StatusBarPanel^ panel1 = gcnew StatusBarPanel;
      StatusBarPanel^ panel2 = gcnew StatusBarPanel;

      // Display the first panel with a sunken border style.
      panel1->BorderStyle = StatusBarPanelBorderStyle::Sunken;

      // Initialize the text of the panel.
      panel1->Text = "Ready...";

      // Set the AutoSize property to use all remaining space on the StatusBar.
      panel1->AutoSize = StatusBarPanelAutoSize::Spring;

      // Display the second panel with a raised border style.
      panel2->BorderStyle = StatusBarPanelBorderStyle::Raised;

      // Create ToolTip text that displays the time the application
      // was started.
      panel2->ToolTipText = System::DateTime::Now.ToShortTimeString();

      // Set the text of the panel to the current date.
      panel2->Text = "Started: " + System::DateTime::Today.ToLongDateString();

      // Set the AutoSize property to size the panel to the size of the contents.
      panel2->AutoSize = StatusBarPanelAutoSize::Contents;

      // Display panels in the StatusBar control.
      statusBar1->ShowPanels = true;

      // Add both panels to the StatusBarPanelCollection of the StatusBar.   
      statusBar1->Panels->Add( panel1 );
      statusBar1->Panels->Add( panel2 );

      // Add the StatusBar to the form.
      this->Controls->Add( statusBar1 );
   }
private void CreateMyStatusBar()
{
    // Create a StatusBar control.
    StatusBar statusBar1 = new StatusBar();

    // Create two StatusBarPanel objects to display in the StatusBar.
    StatusBarPanel panel1 = new StatusBarPanel();
    StatusBarPanel panel2 = new StatusBarPanel();

    // Display the first panel with a sunken border style.
    panel1.set_BorderStyle(StatusBarPanelBorderStyle.Sunken);

    // Initialize the text of the panel.
    panel1.set_Text("Ready...");

    // Set the AutoSize property to use all remaining space on the StatusBar.
    panel1.set_AutoSize(StatusBarPanelAutoSize.Spring);

    // Display the second panel with a raised border style.
    panel2.set_BorderStyle(StatusBarPanelBorderStyle.Raised);

    // Create ToolTip text that displays the time the application was started.
    panel2.set_ToolTipText("Started: " + System.DateTime.get_Now().ToShortTimeString());
    
// Set the text of the panel to the current date.
    panel2.set_Text(System.DateTime.get_Today().ToLongDateString());
    
// Set the AutoSize property to size the panel to the size of the 
    // contents.
    panel2.set_AutoSize(StatusBarPanelAutoSize.Contents);
    // Display panels in the StatusBar control.
    statusBar1.set_ShowPanels(true);
    // Add both panels to the StatusBarPanelCollection of the StatusBar.    
    statusBar1.get_Panels().Add(panel1);
    statusBar1.get_Panels().Add(panel2);
    // Add the StatusBar to the form.
    this.get_Controls().Add(statusBar1);
} //CreateMyStatusBar

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

StatusBar 类
StatusBar 成员
System.Windows.Forms 命名空间
StatusBarPanel