如何:向 StatusBar 控件添加面板
重要
StatusStrip 和 ToolStripStatusLabel 控件取代了 StatusBar 和 StatusBarPanel 控件并向其中添加了新功能;但也可选择保留 StatusBar 和 StatusBarPanel 控件以备后向兼容和供将来使用。
StatusBar 控件控件中的可编程区域由 StatusBarPanel 类的实例组成。 通过 StatusBar.StatusBarPanelCollection 类来添加这些实例。
将面板添加到状态栏
通过在过程中将状态栏面板添加到 StatusBar.StatusBarPanelCollection 来对其进行创建。 使用通过 Panels 属性传递的索引,指定各个面板的属性设置。
在下面的代码示例中,为图标位置设置的路径是 My Documents 文件夹。 使用此位置是因为大多数运行 Windows 操作系统的计算机都包含此文件夹。 选择此位置还使得系统访问级别最低的用户能够安全运行应用程序。 以下示例需要一个已添加 StatusBar 控件的窗体。
注意
StatusBar.StatusBarPanelCollection 是从零开始的集合,因此代码应相应地继续。
Public Sub CreateStatusBarPanels() ' Create panels and set text property. StatusBar1.Panels.Add("One") StatusBar1.Panels.Add("Two") StatusBar1.Panels.Add("Three") ' Set properties of StatusBar panels. ' Set AutoSize property of panels. StatusBar1.Panels(0).AutoSize = StatusBarPanelAutoSize.Spring StatusBar1.Panels(1).AutoSize = StatusBarPanelAutoSize.Contents StatusBar1.Panels(2).AutoSize = StatusBarPanelAutoSize.Contents ' Set BorderStyle property of panels. StatusBar1.Panels(0).BorderStyle = StatusBarPanelBorderStyle.Raised StatusBar1.Panels(1).BorderStyle = StatusBarPanelBorderStyle.Sunken StatusBar1.Panels(2).BorderStyle = StatusBarPanelBorderStyle.Raised ' Set Icon property of third panel. You should replace the bolded ' icon in the sample below with an icon of your own choosing. StatusBar1.Panels(2).Icon = New _ System.Drawing.Icon(System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ & "\Icon.ico") StatusBar1.ShowPanels = True End Sub
public void CreateStatusBarPanels() { // Create panels and set text property. statusBar1.Panels.Add("One"); statusBar1.Panels.Add("Two"); statusBar1.Panels.Add("Three"); // Set properties of StatusBar panels. // Set AutoSize property of panels. statusBar1.Panels[0].AutoSize = StatusBarPanelAutoSize.Spring; statusBar1.Panels[1].AutoSize = StatusBarPanelAutoSize.Contents; statusBar1.Panels[2].AutoSize = StatusBarPanelAutoSize.Contents; // Set BorderStyle property of panels. statusBar1.Panels[0].BorderStyle = StatusBarPanelBorderStyle.Raised; statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken; statusBar1.Panels[2].BorderStyle = StatusBarPanelBorderStyle.Raised; // Set Icon property of third panel. You should replace the bolded // icon in the sample below with an icon of your own choosing. // Note the escape character used (@) when specifying the path. statusBar1.Panels[2].Icon = new System.Drawing.Icon (System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ + @"\Icon.ico"); statusBar1.ShowPanels = true; }
public: void CreateStatusBarPanels() { // Create panels and set text property. statusBar1->Panels->Add("One"); statusBar1->Panels->Add("Two"); statusBar1->Panels->Add("Three"); // Set properties of StatusBar panels. // Set AutoSize property of panels. statusBar1->Panels[0]->AutoSize = StatusBarPanelAutoSize::Spring; statusBar1->Panels[1]->AutoSize = StatusBarPanelAutoSize::Contents; statusBar1->Panels[2]->AutoSize = StatusBarPanelAutoSize::Contents; // Set BorderStyle property of panels. statusBar1->Panels[0]->BorderStyle = StatusBarPanelBorderStyle::Raised; statusBar1->Panels[1]->BorderStyle = StatusBarPanelBorderStyle::Sunken; statusBar1->Panels[2]->BorderStyle = StatusBarPanelBorderStyle::Raised; // Set Icon property of third panel. // You should replace the bolded image // in the sample below with an icon of your own choosing. statusBar1->Panels[2]->Icon = gcnew System::Drawing::Icon(String::Concat( System::Environment::GetFolderPath( System::Environment::SpecialFolder::Personal), "\\Icon.ico")); statusBar1->ShowPanels = true; }