StatusBarPanel 类

表示 StatusBar 控件中的一个面板。虽然 StatusStrip 控件对以前版本的 StatusBar 控件的功能进行替换和添加,但是考虑到向后兼容性和将来的使用(如果您选择),仍然保留了 StatusBar

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

语法

声明
Public Class StatusBarPanel
    Inherits Component
    Implements ISupportInitialize
用法
Dim instance As StatusBarPanel
public class StatusBarPanel : Component, ISupportInitialize
public ref class StatusBarPanel : public Component, ISupportInitialize
public class StatusBarPanel extends Component implements ISupportInitialize
public class StatusBarPanel extends Component implements ISupportInitialize

备注

StatusBarPanel 表示 StatusBar 控件的 StatusBar.StatusBarPanelCollection 中的单个面板。StatusBarPanel 可包含文本和/或图标,用于反映应用程序的状态。使用 StatusBar.StatusBarPanelCollection(可通过 StatusBar 控件的 StatusBar.Panels 属性进行访问)可检索、添加或移除单个 StatusBarPanel

使用 StatusBarPanel 提供的属性可以修改 StatusBar 控件中的面板的显示行为。可以使用 Icon 属性来显示面板中的图标。此属性可用来提供应用程序中状态的图形化表示形式。Alignment 属性使您可以指定面板中文本和/或图标的对齐方式。若要确保面板的大小适合面板的文本,可以使用 AutoSize 属性自动调整面板的大小,以适合面板的文本或填充 StatusBar 控件中的剩余空间。MinWidth 属性使您可以指定面板的最小宽度,以确保它不会比要显示的数据还小。

StatusBar 控件通常用于显示应用程序的帮助信息或状态信息。通常,它对于显示有关出现在面板中的数据的附加信息来说是非常重要的。可以使用 ToolTipText 属性在鼠标指针悬停在面板上时显示信息。

虽然 StatusBar 控件通常用来显示文本信息,但也可以向 StatusBarPanel 提供自己的显示类型。Style 属性使您可以指定描述 StatusBarPanel 的方式。默认情况下,Style 属性用于显示 Text 属性的值(如果在 Icon 属性中指定了图标,则还可以显示图标)。如果该属性设置为 OwnerDraw,则可以将自己的信息描述到面板中。可以使用此功能在面板中描述进度栏或动态图标。

创建 StatusBarPanel 类的实例时,读/写属性会设置为初始值。有关这些值的列表,请参见 StatusBarPanel 构造函数。

示例

下面的代码示例在窗体上创建一个 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

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      System.Windows.Forms.StatusBarPanel

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、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

请参见

参考

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