StatusBarPanel 类

定义

表示 StatusBar 控件中的一个面板。Represents a panel in a StatusBar control. 虽然 StatusStrip 控件对以前版本的 StatusBar 控件的功能进行替换和添加,但是考虑到向后兼容性和将来的使用(如果您选择),仍然保留了 StatusBarAlthough the StatusStrip control replaces and adds functionality to the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.

public ref class StatusBarPanel : System::ComponentModel::Component, System::ComponentModel::ISupportInitialize
public class StatusBarPanel : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize
type StatusBarPanel = class
    inherit Component
    interface ISupportInitialize
Public Class StatusBarPanel
Inherits Component
Implements ISupportInitialize
继承
实现

示例

下面的代码示例在窗StatusBar体上创建了一个控件并StatusBarPanel添加了两个对象。The following code example creates a StatusBar control on a form and adds two StatusBarPanel objects. 首先StatusBarPanel, 命名panel1为, 显示应用程序的状态文本。The first StatusBarPanel, named panel1, displays status text for an application. 第二StatusBarPanel个名panel2为的, 它显示ToolTipText当前日期, 并StatusBarPanel使用类的属性来显示当前时间。The second StatusBarPanel, named panel2, displays the current date and uses the ToolTipText property of the StatusBarPanel class to display the current time. ShowPanels该示例使用属性来确保显示面板而不是标准面板, 并Add Panels使用属性访问的StatusBar.StatusBarPanelCollection方法以将面板添加到StatusBar中。The example uses the ShowPanels property to ensure that the panels are displayed instead of a standard panel, and it uses the Panels property to access the Add method of the StatusBar.StatusBarPanelCollection to add the panels to the StatusBar. 该示例还使用AutoSizeBorderStyleToolTipTextText属性对StatusBarPanel对象进行初始化。The example also uses the AutoSize, BorderStyle, ToolTipText, and Text properties to initialize the StatusBarPanel objects. 此示例假定在示例中定义的方法是从的Form构造函数定义和调用的。This example assumes that the method defined in the example is defined and called from the constructor of a 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

注解

表示控件的StatusBar.StatusBarPanelCollection中的单个面板。 StatusBar StatusBarPanelA StatusBarPanel represents an individual panel in the StatusBar.StatusBarPanelCollection of a StatusBar control. StatusBarPanel可以包含文本和/或图标, 可用于反映应用程序的状态。A StatusBarPanel can contain text and/or an icon that can be used to reflect the status of an application. 使用可StatusBar通过控件的StatusBarPanel属性访问、检索、添加或删除个人。 StatusBar.Panels StatusBar.StatusBarPanelCollectionUse the StatusBar.StatusBarPanelCollection, accessible through the StatusBar.Panels property of a StatusBar control, to retrieve, add, or remove an individual StatusBarPanel.

提供的属性可用于修改StatusBar控件内面板的显示行为。 StatusBarPanelThe StatusBarPanel provides properties that enable you to modify the display behavior of a panel within a StatusBar control. 您可以使用Icon属性在面板中显示图标。You can use the Icon property to display an icon within a panel. 此属性可用于在应用程序中提供状态的图形化表示形式。This property can be used to provide a graphical representation of state in an application. 使用Alignment属性可以指定面板内文本和/或图标的对齐方式。The Alignment property enables you to specify how text and/or an icon is aligned within the panel. 若要确保面板大小正确调整以适应面板的文本, 可以使用AutoSize属性来自动调整面板的大小以适合面板的文本或填充StatusBar控件内的剩余空间。To ensure that your panel is sized properly to fit the text of the panel, you can use the AutoSize property to automatically resize the panel to fit the text of the panel or to fill the remaining space within the StatusBar control. 使用MinWidth属性可以指定面板的最小宽度, 以确保它不会小于其要显示的数据。The MinWidth property enables you to specify a minimum width for the panel to ensure that it does not get smaller than the data it is intended to display.

StatusBar控件通常用于显示有关应用程序的帮助信息或状态信息。The StatusBar control is typically used to display Help information or state information about your application. 通常, 要显示有关面板中显示的数据的其他信息, 这一点很重要。Often, it is important to display additional information about data that is presented in a panel. 当鼠标指针停留ToolTipText在面板上时, 可以使用属性来显示信息。You can use the ToolTipText property to display information whenever the mouse pointer rests on a panel.

尽管控件通常用于显示文本信息, 但您也可以StatusBarPanel向提供自己的显示类型。 StatusBarAlthough the StatusBar control is typically used to display textual information, you can also provide your own type of display to a StatusBarPanel. 属性使您能够指定StatusBarPanel将如何绘制。 StyleThe Style property enables you to specify how the StatusBarPanel will be drawn. 默认情况下, Style属性用于显示Text属性的值 (如果在Icon属性中指定, 则显示一个图标)。By default, the Style property is used to display the value of the Text property (and an icon, if specified in the Icon property). 如果将属性设置为OwnerDraw, 则可以在面板中绘制自己的信息。If the property is set to OwnerDraw, you can draw your own information into the panel. 您可以使用此功能在面板中绘制进度栏或动画图标。You can use this feature to draw a progress bar or an animated icon in the panel.

创建StatusBarPanel类的实例时, 读/写属性将设置为初始值。When you create an instance of the StatusBarPanel class, the read/write properties are set to initial values. 有关这些值的列表, 请参见StatusBarPanel构造函数。For a list of these values, see the StatusBarPanel constructor.

构造函数

StatusBarPanel()

初始化 StatusBarPanel 类的新实例。Initializes a new instance of the StatusBarPanel class.

属性

Alignment

获取或设置状态栏面板中文本和图标的对齐方式。Gets or sets the alignment of text and icons within the status bar panel.

AutoSize

获取或设置一个值,该值指示是否自动调整状态栏面板的大小。Gets or sets a value indicating whether the status bar panel is automatically resized.

BorderStyle

获取或设置状态栏面板的边框样式。Gets or sets the border style of the status bar panel.

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
Icon

获取或设置要显示在状态栏面板中的图标。Gets or sets the icon to display within the status bar panel.

MinWidth

获取或设置 StatusBar 控件中状态栏面板的最小允许宽度。Gets or sets the minimum allowed width of the status bar panel within the StatusBar control.

Name

获取或设置应用于 StatusBarPanel 的名称。Gets or sets the name to apply to the StatusBarPanel.

Parent

获取承载状态栏面板的 StatusBar 控件。Gets the StatusBar control that hosts the status bar panel.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
Style

获取或设置状态栏面板的样式。Gets or sets the style of the status bar panel.

Tag

获取或设置包含有关 StatusBarPanel 的数据的对象。Gets or sets an object that contains data about the StatusBarPanel.

Text

获取或设置状态栏面板的文本。Gets or sets the text of the status bar panel.

ToolTipText

获取或设置与状态栏面板关联的工具提示文本。Gets or sets ToolTip text associated with the status bar panel.

Width

获取或设置 StatusBar 控件中状态栏面板的宽度。Gets or sets the width of the status bar panel within the StatusBar control.

方法

BeginInit()

开始 StatusBarPanel 的初始化。Begins the initialization of a StatusBarPanel.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 StatusBarPanel 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the StatusBarPanel and optionally releases the managed resources.

EndInit()

结束 StatusBarPanel 的初始化。Ends the initialization of a StatusBarPanel.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ToString()

检索一个字符串,该字符串包含面板的信息。Retrieves a string that contains information about the panel.

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

适用于

另请参阅