通常 StatusBar 控件由 StatusBarPanel 对象组成,其中每个对象都显示文本和/或图标。也可以提供所有者描述的面板来提供自定义面板,
例如进度栏或一系列显示应用程序状态的图像。StatusBar 控件通常显示关于正在 Form 上查看的对象或该对象的组件的信息,或显示与该
对象在应用程序中操作相关的上下文信息。
例如进度栏或一系列显示应用程序状态的图像。StatusBar 控件通常显示关于正在 Form 上查看的对象或该对象的组件的信息,或显示与该
对象在应用程序中操作相关的上下文信息。
StatusBar 控件提供了使您可以自定义控件外观的属性。若 StatusBar 显示在一个可调整大小的窗体上,则可使用 SizingGrip 属性在该窗
体的右下角显示一个大小调整手柄来向用户指示该窗体可以调整大小。ShowPanels 属性使您可以显示 StatusBar 内的面板,或仅显示控件的
Text 属性值。
体的右下角显示一个大小调整手柄来向用户指示该窗体可以调整大小。ShowPanels 属性使您可以显示 StatusBar 内的面板,或仅显示控件的
Text 属性值。
默认的 StatusBar 没有面板。若要向 StatusBar 中添加面板,可以使用 StatusBar.StatusBarPanelCollection 类的 Add 方法,该类可以
通过控件的 Panels 属性进行访问。也可以使用通过 Panels 属性提供的 StatusBar.StatusBarPanelCollection 对象从控件中移除面板和访
问用于操作面板的特定 StatusBarPanel 对象。
通过控件的 Panels 属性进行访问。也可以使用通过 Panels 属性提供的 StatusBar.StatusBarPanelCollection 对象从控件中移除面板和访
问用于操作面板的特定 StatusBarPanel 对象。
若要确定 StatusBar 控件内的 StatusBarPanel 对象何时被单击,则可以为 PanelClick 事件创建一个事件处理程序。若要在面板上执行所
有者描述的操作,则可以为 DrawItem 事件创建一个事件处理程序。传递到事件处理程序的事件数据提供了关于要描述的面板和用来执行描述
任务的 Graphics 对象的信息。
有者描述的操作,则可以为 DrawItem 事件创建一个事件处理程序。传递到事件处理程序的事件数据提供了关于要描述的面板和用来执行描述
任务的 Graphics 对象的信息。
创建 StatusBar 的实例时,读/写属性将被设置为初始值。有关这些值的列表,请参见 StatusBar 构造函数。
C#]
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();
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 the current time.
panel2.ToolTipText = 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;
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 current time.
panel2.ToolTipText = 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);
statusBar1.Panels.Add(panel2);
// Add the StatusBar to the form.
this.Controls.Add(statusBar1);
}
this.Controls.Add(statusBar1);
}