Use Label as status bar : StatusBar « GUI Windows Form « C# / C Sharp






Use Label as status bar

Use Label as status bar

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    private System.Windows.Forms.Label lblCount;
    List<Rectangle> squares = new List<Rectangle>();

  public Form1() {
        InitializeComponent();
        
  }
    private void NonOptimizedSquares_Paint(object sender, PaintEventArgs e)
    {
      Pen pen = new Pen(Color.Red, 10);
      foreach (Rectangle square in squares) {
        e.Graphics.DrawRectangle(pen, square);
      }
      pen.Dispose();
      lblCount.Text = " " + squares.Count.ToString() + " squares"; 
    }

    private void NonOptimizedSquares_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        Rectangle square = new Rectangle(e.X, e.Y, 20, 20);
        squares.Add(square);
                square.Inflate(1, 1);
                Invalidate(square);
      } 
    }

    private void InitializeComponent()
    {
      this.lblCount = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // lblCount
      // 
      this.lblCount.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblCount.Dock = System.Windows.Forms.DockStyle.Bottom;
      this.lblCount.Location = new System.Drawing.Point(0, 251);
      this.lblCount.Name = "lblCount";
      this.lblCount.Padding = new System.Windows.Forms.Padding(2);
      this.lblCount.Size = new System.Drawing.Size(299, 21);
      this.lblCount.TabIndex = 0;
      // 
      // NonOptimizedSquares
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(299, 272);
      this.Controls.Add(this.lblCount);
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.Name = "NonOptimizedSquares";
      this.Text = "NonOptimizedSquares";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.NonOptimizedSquares_Paint);
      this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.NonOptimizedSquares_MouseDown);
      this.ResumeLayout(false);

    }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}


           
       








Related examples in the same category

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