Use StatusBarPanel : StatusBar « GUI Windows Form « C# / C Sharp






Use StatusBarPanel

 



using System;
using System.Drawing;
using System.Windows.Forms;
   
class MenuHelpFirstTry: Form
{
     StatusBarPanel sbpMenuHelp;
     string         strSavePanelText;
   
     public static void Main()
     {
          Application.Run(new MenuHelpFirstTry());
     }
     public MenuHelpFirstTry()
     {
   
          StatusBar sb = new StatusBar();
          sb.Parent = this;
          sb.ShowPanels = true;
   
          sbpMenuHelp = new StatusBarPanel();
          sbpMenuHelp.Text = "Ready";
          sbpMenuHelp.AutoSize = StatusBarPanelAutoSize.Spring;
   
          sb.Panels.Add(sbpMenuHelp);
   
          Menu = new MainMenu();
          EventHandler ehSelect = new EventHandler(MenuOnSelect);
          
          MenuItem mi = new MenuItem("File");
          mi.Select += ehSelect;
          Menu.MenuItems.Add(mi);
   
          mi = new MenuItem("Open");
          mi.Select += ehSelect;
          Menu.MenuItems[0].MenuItems.Add(mi);
   
          mi = new MenuItem("Close");
          mi.Select += ehSelect;
          Menu.MenuItems[0].MenuItems.Add(mi);
   
          mi = new MenuItem("Save");
          mi.Select += ehSelect;
          Menu.MenuItems[0].MenuItems.Add(mi);
   
          mi = new MenuItem("Edit");
          mi.Select += ehSelect;
          Menu.MenuItems.Add(mi);
   
          mi = new MenuItem("Cut");
          mi.Select += ehSelect;
          Menu.MenuItems[1].MenuItems.Add(mi);
          
          mi = new MenuItem("Copy");
          mi.Select += ehSelect;
          Menu.MenuItems[1].MenuItems.Add(mi);
   
          mi = new MenuItem("Paste");
          mi.Select += ehSelect;
          Menu.MenuItems[1].MenuItems.Add(mi);
     }
     protected override void OnMenuStart(EventArgs ea)
     {
          strSavePanelText = sbpMenuHelp.Text;
     }
     protected override void OnMenuComplete(EventArgs ea)
     {
          sbpMenuHelp.Text = strSavePanelText;
     }
     void MenuOnSelect(object obj, EventArgs ea)
     {
          MenuItem mi = (MenuItem) obj;
          string   str;
   
          switch (mi.Text)
          {
              case "File":   str = "file";    break;
              case "Open":   str = "Open";         break;
              case "Close":  str = "Close";        break;
              case "Save":   str = "Save";         break;
              case "Edit":   str = "edit";  break;
              case "Cut":    str = "cut";         break;
              case "Copy":   str = "Copy";                          break;
              case "Paste":  str = "Paste";        break;
              default:       str = "";                                   break;
          }
   
          sbpMenuHelp.Text = str;
     }
}

 








Related examples in the same category

1.Display message in StatusBar
2.Use Label as status barUse Label as status bar
3.Add icon to statusbarAdd icon to statusbar
4.Display current time on statusbarDisplay current time on statusbar
5.Display menu item alert message on the statusbarDisplay menu item alert message on the statusbar
6.StatusBar with two panelsStatusBar with two panels
7.Status bar: display time and prompt message for menu itemStatus bar: display time and prompt message for menu item
8.StatusBar ExampleStatusBar Example
9.Status Strip Example
10.Add StatusPanels to StatusBar
11.Set Text to Statusbar