C# 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();
  }
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章