Instrukcje: dodawanie paneli do kontrolki StatusBar
Ważny
Kontrolki StatusStrip i ToolStripStatusLabel zastępują i dodają funkcje do kontrolek StatusBar i StatusBarPanel; jednak kontrolki StatusBar i StatusBarPanel są zachowywane w celu zachowania zgodności z poprzednimi wersjami i użycia w przyszłości, jeśli wybierzesz.
Programowalny obszar w kontrolce StatusBar składa się z wystąpień klasy StatusBarPanel. Są one dodawane za pomocą dodatków do klasy StatusBar.StatusBarPanelCollection.
Aby dodać panele do paska stanu
W procedurze utwórz panele paska stanu, dodając je do StatusBar.StatusBarPanelCollection. Określ ustawienia właściwości dla poszczególnych paneli przy użyciu ich indeksu przekazywanego przez właściwość Panels.
W poniższym przykładzie kodu ścieżka ustawiona dla lokalizacji ikony to folder Moje dokumenty. Ta lokalizacja jest używana, ponieważ można założyć, że większość komputerów z systemem operacyjnym Windows będzie zawierać ten folder. Wybranie tej lokalizacji umożliwia również użytkownikom z minimalnymi poziomami dostępu systemu do bezpiecznego uruchamiania aplikacji. Aby poniższy przykład zadziałał, formularz musi mieć już dodany formant StatusBar.
Notatka
StatusBar.StatusBarPanelCollection jest kolekcją indeksowaną od zera, więc kod powinien być zgodny z tym.
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; }
Zobacz też
.NET Desktop feedback