C # StatusStrip status bar routine

Source: Internet
Author: User

Effect:
Display the status bar of the form through statusstrip
At the same time, the status bar is divided into three parts
Display text information on the left
Blank in the middle
Display time information on the right side

Statusstrip sb = new statusstrip ();

Toolstriplabel TSL = new toolstriplabel (); // defines controls in the statusstrip project, where toolstriplabel is a label-like control and is now used to display text

TSL. Text = "test"; // text to be displayed

Toolstripitem [] TSI = new toolstripitem [1]; // defines a project in statusstrip
Tsi [0] = TSL;

SB. Items. addrange (TSI); // Add the project to statusstrip

This. Controls. Add (sb); // Add StatusStrip to the form

1. Create a form and add StatusStrip
The default StatusStrip name is statusStrip1.

2. In the Items attribute of statusStrip1
Add three statuslabels
Default names: toolStripStatusLabel1, 2, 3
Sort by 1, 2, 3

3. Modify the Text attribute of toolStripStatusLabel1
For related text, such as "welcome to use this system"

4. Modify the Text attribute of toolStripStatusLabel2 to null.
The Sprint attribute is True.
The BorderSides attribute is Left and Right.

5. Modify the Text attribute of toolStripStatusLabel3 to null.
In the Form Load event, modify the display time to the current time.
This. toolStripStatusLabel3.Text = "Logon Time:" + DateTime. Now. ToString ("yyyy-MM-dd hh: mm: ss ");

6. If you want to keep the status bar time information changing with the current operating system time
You can add the Timer control to implement
Added Timer control timer1
Compile the Tick event
P rivate void timereffectick (object sender, EventArgs e)
{
This. toolStripStatusLabel3.Text = "current system time:" + DateTime. Now. ToString ("yyyy-MM-dd hh: mm: ss ");
}

Set timer1 in the Form Load event
P rivate void MainForm_Load (object sender, EventArgs e)
{
This. toolStripStatusLabel3.Text = "current system time:" + DateTime. Now. ToString ("yyyy-MM-dd hh: mm: ss ");
This. timer1.Interval = 1000;
This. timer1.Start ();
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.