Add Icon to StatusBar : StatusBar « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » StatusBar 
23.25.3.Add Icon to StatusBar
Add Icon to StatusBar
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class FormWithStatusBarIcon : System.Windows.Forms.Form
{
  private StatusBar statusBar = new StatusBar();
  private StatusBarPanel sbPnlPrompt = new StatusBarPanel();
  private StatusBarPanel sbPnlTime = new StatusBarPanel();

  private Timer timer1 = new Timer();
  private MainMenu mainMenu;
  private System.ComponentModel.Container components;

  public FormWithStatusBarIcon()
  {
    InitializeComponent();

    timer1.Interval = 1000;
    timer1.Enabled = true;
    timer1.Tick += new EventHandler(timer1_Tick);
    this.MenuComplete += new EventHandler(StatusForm_MenuDone);
    BuildMenuSystem();
    BuildStatBar();
  }

  protected override void Disposebool disposing )
  {
    ifdisposing )
    {
      if (components != null
      {
        components.Dispose();
      }
    }
    base.Disposedisposing );
  }

  private void InitializeComponent()
  {
    this.components = new System.ComponentModel.Container();
    this.Size = new System.Drawing.Size(300,300);
    this.Text = "Form1";
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new FormWithStatusBarIcon());
  }

  private void FileExit_Clicked(object sender, EventArgs e
  {    
    this.Close();
  }
    
  private void HelpAbout_Clicked(object sender, EventArgs e
  {
    sbPnlPrompt.Text = "Help";
  }
    
  private void FileExit_Selected(object sender, EventArgs e
  {
    sbPnlPrompt.Text = "Terminates this app";     
  }

  private void HelpAbout_Selected(object sender, EventArgs e
  {
    sbPnlPrompt.Text = "Displays app info";
  }

  private void StatusForm_MenuDone(object sender, EventArgs e
  {
    sbPnlPrompt.Text = "Ready";
  }

  private void timer1_Tick(object sender, EventArgs e
  {
    DateTime t = DateTime.Now;
    string s = t.ToLongTimeString() ;
    sbPnlTime.Text = s ;    
  }

  private void BuildMenuSystem()
  {
    mainMenu = new MainMenu();
    
    MenuItem miFile = mainMenu.MenuItems.Add("&File");          
    miFile.MenuItems.Add(new MenuItem("E&xit"new EventHandler(this.FileExit_Clicked),Shortcut.CtrlX));
    miFile.MenuItems[0].Select += new EventHandler(FileExit_Selected);

    MenuItem miHelp = mainMenu.MenuItems.Add("Help");  
    miHelp.MenuItems.Add(new MenuItem("&About",new EventHandler(this.HelpAbout_Clicked),Shortcut.CtrlA));
    miHelp.MenuItems[0].Select += new EventHandler(HelpAbout_Selected);

    this.Menu = mainMenu;      
  }

  private void BuildStatBar()
  {
    statusBar.ShowPanels = true;
    statusBar.Panels.AddRange(new StatusBarPanel[] {sbPnlPrompt, sbPnlTime});
    
    sbPnlPrompt.BorderStyle = StatusBarPanelBorderStyle.None;
    sbPnlPrompt.AutoSize = StatusBarPanelAutoSize.Spring;
    sbPnlPrompt.Width = 62;
    sbPnlPrompt.Text = "Ready";

    Icon i = new Icon("status.ico");
    sbPnlPrompt.Icon = i;
    
    sbPnlTime.Alignment = HorizontalAlignment.Right;
    sbPnlTime.Width = 76;

    this.Controls.Add(statusBar);  
  }
}
23.25.StatusBar
23.25.1.Simple Status Bar with Panel
23.25.2.Form with StatusBarForm with StatusBar
23.25.3.Add Icon to StatusBarAdd Icon to StatusBar
23.25.4.Date and Time in StatusBar
23.25.5.Status Bar and Auto-Scroll
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.