天天看點

winForm狀态欄StatusStrip

c# winForm 将窗體狀态欄StatusStrip 分成左中右三部分 右邊顯示目前時間

實作效果:

通過StatusStrip顯示窗體狀态欄

同時将狀态欄分成三部分

居左邊顯示相關文字資訊

中間空白顯示

居右邊顯示時間資訊

1.建立窗體及添加StatusStrip

預設StatusStrip名稱為statusStrip1

2.在statusStrip1的Items屬性中

添加三個StatusLabel

預設名稱為toolStripStatusLabel1,2,3

按1,2,3的順序排列

3.修改toolStripStatusLabel1的Text屬性

為相關文字如"歡迎使用本系統"

4.修改toolStripStatusLabel2的Text屬性 為空

Sprint屬性為True

BorderSides屬性為Left,Right

5.修改toolStripStatusLabel3的Text屬性 為空

在Form的Load事件中 修改其顯示為目前時間

this.toolStripStatusLabel3.Text = "登入時間:" + DateTime.Now.ToString("yyyy-MM-dd

hh:mm:ss");

6.如果要使狀态欄時間資訊随作業系統目前時間不停的改變

則可以通過增加Timer控件來實作

增加Timer控件 timer1

編寫其Tick事件為

private void timer1_Tick(object sender, EventArgs e)

{

this.toolStripStatusLabel3.Text = "系統目前時間:" + DateTime.Now.ToString("yyyy-

MM-dd hh:mm:ss");

}

在Form的Load事件中 對timer1進行相關設定

private void MainForm_Load(object sender, EventArgs e)

{

this.toolStripStatusLabel3.Text = "系統目前時間:" + DateTime.Now.ToString("yyyy-

MM-dd hh:mm:ss");

this.timer1.Interval=1000;

this.timer1.Start();

}