Status Strip Example : StatusBar « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » GUI Windows Form » StatusBarScreenshots 
Status Strip Example
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

enum DateTimeFormat {
    ShowClock,
    ShowDay
}

public class MainWindow : Form {
    DateTimeFormat dtFormat = DateTimeFormat.ShowClock;
    private ToolStripMenuItem currentCheckedItem;

    public MainWindow() {
        InitializeComponent();
        BackColor = Color.CadetBlue;
        currentCheckedItem = currentTimeToolStripMenuItem;
        currentCheckedItem.Checked = true;
    }
    private void timerDateTimeUpdate_Tick(object sender, EventArgs e) {
        string panelInfo = "";
        if (dtFormat == DateTimeFormat.ShowClock)
            panelInfo = DateTime.Now.ToLongTimeString();
        else
            panelInfo = DateTime.Now.ToLongDateString();
        toolStripStatusLabelClock.Text = panelInfo;
    }
    private void currentTimeToolStripMenuItem_Click(object sender, EventArgs e) {
        currentCheckedItem.Checked = false;
        dtFormat = DateTimeFormat.ShowClock;
        currentCheckedItem = currentTimeToolStripMenuItem;
        currentCheckedItem.Checked = true;
    }

    private void dayoftheWeekToolStripMenuItem_Click(object sender, EventArgs e) {
        currentCheckedItem.Checked = false;
        dtFormat = DateTimeFormat.ShowDay;
        currentCheckedItem = dayoftheWeekToolStripMenuItem;
        currentCheckedItem.Checked = true;
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
        Application.Exit();
    }

    private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
        MessageBox.Show("My StatusStripApp!");
    }

    private void exitToolStripMenuItem_MouseHover(object sender, EventArgs e) {
        toolStripStatusLabelMenuState.Text = "Exits the app.";
    }

    private void aboutToolStripMenuItem_MouseHover(object sender, EventArgs e) {
        toolStripStatusLabelMenuState.Text = "Shows about box.";
    }

    private void dayoftheWeekToolStripMenuItem_MouseHover(object sender, EventArgs e) {
        toolStripStatusLabelMenuState.Text = "Shows the day of the week.";
    }

    private void currentTimeToolStripMenuItem_MouseHover(object sender, EventArgs e) {
        toolStripStatusLabelMenuState.Text = "Shows the current time.";
    }

    private void SetReadyPrompt(object sender, EventArgs e) {
        toolStripStatusLabelMenuState.Text = "Ready.";
    }

    private void InitializeComponent() {
        this.mainStatusStrip = new System.Windows.Forms.StatusStrip();
        this.toolStripStatusLabelMenuState = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripStatusLabelClock = new System.Windows.Forms.ToolStripStatusLabel();
        this.toolStripDropDownButtonDateTime = new System.Windows.Forms.ToolStripDropDownButton();
        this.dayoftheWeekToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.currentTimeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.menuStrip1 = new System.Windows.Forms.MenuStrip();
        this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.timerDateTimeUpdate = new System.Windows.Forms.Timer();
        this.mainStatusStrip.SuspendLayout();
        this.menuStrip1.SuspendLayout();
        this.SuspendLayout();
        // 
        // mainStatusStrip
        // 
        this.mainStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripStatusLabelMenuState,
            this.toolStripStatusLabelClock,
            this.toolStripDropDownButtonDateTime});
        this.mainStatusStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Table;
        this.mainStatusStrip.Location = new System.Drawing.Point(078);
        this.mainStatusStrip.Name = "mainStatusStrip";
        this.mainStatusStrip.Size = new System.Drawing.Size(36127);
        this.mainStatusStrip.TabIndex = 0;
        this.mainStatusStrip.Text = "statusStrip1";
        // 
        // toolStripStatusLabelMenuState
        // 
        this.toolStripStatusLabelMenuState.Name = "toolStripStatusLabelMenuState";
        this.toolStripStatusLabelMenuState.Spring = true;
        this.toolStripStatusLabelMenuState.TextAlign = System.Drawing.ContentAlignment.TopLeft;
        // 
        // toolStripStatusLabelClock
        // 
        this.toolStripStatusLabelClock.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Top)
                    | System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)
                    | System.Windows.Forms.ToolStripStatusLabelBorderSides.Bottom)));
        this.toolStripStatusLabelClock.Name = "toolStripStatusLabelClock";
        // 
        // toolStripDropDownButtonDateTime
        // 
        this.toolStripDropDownButtonDateTime.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.toolStripDropDownButtonDateTime.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.dayoftheWeekToolStripMenuItem,
            this.currentTimeToolStripMenuItem});
        this.toolStripDropDownButtonDateTime.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripDropDownButtonDateTime.Name = "toolStripDropDownButtonDateTime";
        this.toolStripDropDownButtonDateTime.Text = "toolStripDropDownButton1";
        // 
        // dayoftheWeekToolStripMenuItem
        // 
        this.dayoftheWeekToolStripMenuItem.Name = "dayoftheWeekToolStripMenuItem";
        this.dayoftheWeekToolStripMenuItem.Text = "Day of the Week";
        this.dayoftheWeekToolStripMenuItem.MouseLeave += new System.EventHandler(this.SetReadyPrompt);
        this.dayoftheWeekToolStripMenuItem.MouseHover += new System.EventHandler(this.dayoftheWeekToolStripMenuItem_MouseHover);
        this.dayoftheWeekToolStripMenuItem.Click += new System.EventHandler(this.dayoftheWeekToolStripMenuItem_Click);
        // 
        // currentTimeToolStripMenuItem
        // 
        this.currentTimeToolStripMenuItem.Name = "currentTimeToolStripMenuItem";
        this.currentTimeToolStripMenuItem.Text = "Current Time";
        this.currentTimeToolStripMenuItem.MouseLeave += new System.EventHandler(this.SetReadyPrompt);
        this.currentTimeToolStripMenuItem.MouseHover += new System.EventHandler(this.currentTimeToolStripMenuItem_MouseHover);
        this.currentTimeToolStripMenuItem.Click += new System.EventHandler(this.currentTimeToolStripMenuItem_Click);
        // 
        // menuStrip1
        // 
        this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.helpToolStripMenuItem});
        this.menuStrip1.Location = new System.Drawing.Point(00);
        this.menuStrip1.Name = "menuStrip1";
        this.menuStrip1.Size = new System.Drawing.Size(36124);
        this.menuStrip1.TabIndex = 1;
        this.menuStrip1.Text = "menuStrip1";
        // 
        // fileToolStripMenuItem
        // 
        this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.exitToolStripMenuItem});
        this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
        this.fileToolStripMenuItem.Text = "&File";
        // 
        // exitToolStripMenuItem
        // 
        this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
        this.exitToolStripMenuItem.Text = "E&xit";
        this.exitToolStripMenuItem.MouseLeave += new System.EventHandler(this.SetReadyPrompt);
        this.exitToolStripMenuItem.MouseHover += new System.EventHandler(this.exitToolStripMenuItem_MouseHover);
        this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
        // 
        // helpToolStripMenuItem
        // 
        this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.aboutToolStripMenuItem});
        this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
        this.helpToolStripMenuItem.Text = "&Help";
        // 
        // aboutToolStripMenuItem
        // 
        this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
        this.aboutToolStripMenuItem.Text = "&About";
        this.aboutToolStripMenuItem.MouseLeave += new System.EventHandler(this.SetReadyPrompt);
        this.aboutToolStripMenuItem.MouseHover += new System.EventHandler(this.aboutToolStripMenuItem_MouseHover);
        this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
        // 
        // timerDateTimeUpdate
        // 
        this.timerDateTimeUpdate.Enabled = true;
        this.timerDateTimeUpdate.Interval = 1000;
        this.timerDateTimeUpdate.Tick += new System.EventHandler(this.timerDateTimeUpdate_Tick);
        // 
        // MainWindow
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(361105);
        this.Controls.Add(this.mainStatusStrip);
        this.Controls.Add(this.menuStrip1);
        this.MainMenuStrip = this.menuStrip1;
        this.Name = "MainWindow";
        this.Text = "Form1";
        this.mainStatusStrip.ResumeLayout(false);
        this.menuStrip1.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    private System.Windows.Forms.StatusStrip mainStatusStrip;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelMenuState;
    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelClock;
    private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButtonDateTime;
    private System.Windows.Forms.MenuStrip menuStrip1;
    private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem dayoftheWeekToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem currentTimeToolStripMenuItem;
    private System.Windows.Forms.Timer timerDateTimeUpdate;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new MainWindow());
    }
}

 
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.Use StatusBarPanel
10.Add StatusPanels to StatusBar
11.Set Text to Statusbar
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.