如何:向 StatusBar 控件添加面板
重要
StatusStrip 和 ToolStripStatusLabel 控件替换并添加 StatusBar 和 StatusBarPanel 控件的功能;但是,如果选择,则保留 StatusBar 和 StatusBarPanel 控件以实现向后兼容性和将来使用。
StatusBar 控件 控件中的可编程区域由 StatusBarPanel 类的实例组成。 这些内容是通过向 StatusBar.StatusBarPanelCollection 类添加实现的。
向状态栏添加面板
在此过程中,通过将状态栏面板添加到 StatusBar.StatusBarPanelCollection来创建状态栏面板。 通过使用通过 Panels 属性传递的索引为各个面板指定属性设置。
在以下代码示例中,图标位置设置的路径是“我的文档” 文件夹
。 之所以使用此位置,是因为你可以假定运行 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; }