StatusBarPanel 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 StatusBar 控件中的一个面板。
此类在 .NET 5 及更高版本中不可用。 ToolStripStatusLabel请改用 控件,这将替换并扩展StatusBarPanel控件。
public ref class StatusBarPanel : System::ComponentModel::Component, System::ComponentModel::ISupportInitializepublic class StatusBarPanel : System.ComponentModel.Component, System.ComponentModel.ISupportInitializetype StatusBarPanel = class
    inherit Component
    interface ISupportInitializePublic Class StatusBarPanel
Inherits Component
Implements ISupportInitialize- 继承
- 实现
示例
下面的代码示例在窗体上创建控件 StatusBar 并添加两 StatusBarPanel 个 对象。 名为 的第一个 StatusBarPanelpanel1显示应用程序的状态文本。 名为 的第二 StatusBarPanel个 panel2显示当前日期,并使用 ToolTipText 类的 StatusBarPanel 属性显示当前时间。 该示例使用 ShowPanels 属性来确保显示面板而不是标准面板,并使用 Panels 属性访问 Add 的 StatusBar.StatusBarPanelCollection 方法,将面板添加到 StatusBar。 该示例还使用 AutoSize、 BorderStyle、 ToolTipText和 Text 属性来初始化 StatusBarPanel 对象。 此示例假定示例中定义的方法是从 的构造函数中定义和调用的 Form。
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.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 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
注解
此类在 .NET 5 及更高版本中不可用。 请改用 ToolStripStatusLabel 控件。
表示 StatusBarPanel 控件的 中的 StatusBar.StatusBarPanelCollection 单个 StatusBar 面板。 可以 StatusBarPanel 包含文本和/或可用于反映应用程序状态的图标。 StatusBar.StatusBarPanelCollection使用 可通过 StatusBar.Panels 控件的 属性访问的 StatusBar 来检索、添加或删除单个 StatusBarPanel。
StatusBarPanel提供属性,使你能够修改控件内StatusBar面板的显示行为。 可以使用 Icon 属性在面板中显示图标。 此属性可用于提供应用程序中状态的图形表示形式。 使用 Alignment 属性可以指定文本和/或图标在面板中的对齐方式。 若要确保调整面板的大小以适合面板的文本,可以使用 AutoSize 属性自动调整面板的大小以适应面板的文本或填充控件中的 StatusBar 剩余空间。 使用 MinWidth 属性可以指定面板的最小宽度,以确保它不会小于它要显示的数据。
控件 StatusBar 通常用于显示有关应用程序的帮助信息或状态信息。 通常,显示有关面板中显示的数据的其他信息非常重要。 每当鼠标指针停留在面板上时, ToolTipText 都可以使用 属性显示信息。
StatusBar尽管 控件通常用于显示文本信息,但你也可以向 StatusBarPanel提供自己的显示类型。 使用 Style 属性可以指定 如何 StatusBarPanel 绘制 。 默认情况下, Style 属性用于显示 Text 属性的值 (和图标(如果在属性) 中指定 Icon )。 如果 属性设置为 OwnerDraw,则可以将自己的信息绘制到面板中。 可以使用此功能在面板中绘制进度栏或动画图标。
创建 类的 StatusBarPanel 实例时,读/写属性设置为初始值。 有关这些值的列表,请参阅 StatusBarPanel 构造函数。
构造函数
| StatusBarPanel() | 初始化 StatusBarPanel 类的新实例。 | 
属性
| Alignment | 获取或设置状态栏面板中文本和图标的对齐方式。 | 
| AutoSize | 获取或设置一个值,该值指示是否自动调整状态栏面板的大小。 | 
| BorderStyle | 获取或设置状态栏面板的边框样式。 | 
| CanRaiseEvents | 获取一个指示组件是否可以引发事件的值。(继承自 Component) | 
| Container | 获取包含 IContainer 的 Component。(继承自 Component) | 
| DesignMode | 获取一个值,用以指示 Component 当前是否处于设计模式。(继承自 Component) | 
| Events | 获取附加到此 Component 的事件处理程序的列表。(继承自 Component) | 
| Icon | 获取或设置要显示在状态栏面板中的图标。 | 
| MinWidth | 获取或设置 StatusBar 控件中状态栏面板的最小允许宽度。 | 
| Name | 获取或设置应用于 StatusBarPanel 的名称。 | 
| Parent | 获取承载状态栏面板的 StatusBar 控件。 | 
| Site | (继承自 Component) | 
| Style | 获取或设置状态栏面板的样式。 | 
| Tag | 获取或设置包含有关 StatusBarPanel 的数据的对象。 | 
| Text | 获取或设置状态栏面板的文本。 | 
| ToolTipText | 获取或设置与状态栏面板关联的工具提示文本。 | 
| Width | 获取或设置 StatusBar 控件中状态栏面板的宽度。 | 
方法
| BeginInit() | 开始 StatusBarPanel 的初始化。 | 
| CreateObjRef(Type) | 创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。(继承自 MarshalByRefObject) | 
| Dispose() | 释放由 Component 使用的所有资源。(继承自 Component) | 
| Dispose(Boolean) | 释放由 StatusBarPanel 占用的非托管资源,还可以另外再释放托管资源。 | 
| EndInit() | 结束 StatusBarPanel 的初始化。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetLifetimeService() | 
		已过时.
	 检索控制此实例的生存期策略的当前生存期服务对象。(继承自 MarshalByRefObject) | 
| GetService(Type) | 返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。(继承自 Component) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| InitializeLifetimeService() | 
		已过时.
	 获取生存期服务对象来控制此实例的生存期策略。(继承自 MarshalByRefObject) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| MemberwiseClone(Boolean) | 创建当前 MarshalByRefObject 对象的浅表副本。(继承自 MarshalByRefObject) | 
| ToString() | 检索一个字符串,该字符串包含面板的信息。 | 
事件
| Disposed | 在通过调用 Dispose() 方法释放组件时发生。(继承自 Component) |