C# 學習使用StatusStrip

   先了解一下StatusStrip:首選StatusStrip是Form中的一個控件,同時也是一個大的控件,其中含有許多子控件,這些子控件存放在控件群中。
這樣我們要使用StatusStrip時,首先要定義StatusStrip,然后定義ToolStrip控件,再次定義ToolStrip控件群,第三將ToolStrip控件加入到控件群中,第四將控件群加入到StatusStrip中,最后要將StatusStrip加入到窗體中。

舉例說明:
   本例是在Form窗體中加入任務欄,並在任務欄左邊顯示「Test」。

一、在設計模式下的添加方法為:
    在窗體上添加一個StatusStrip控件。在StatusStrip上添加一個ToolStripLabel控件。將ToolStripLabel控件的Text屬性設置成在運行時顯示的消息(即為Test)。

二、 在代碼模式下添加過程即為:
1. 定義StatusStrip
2. 定義控件(ToolStripLabel)
3. 定義控件群(ToolStripItem)
4. 將控件加入控件群(Items.AddRange)
5. 將StatusStrip加入到Form中

        public Form1()
        {
            InitializeComponent();

            
#region AddStatusStrip

            
//1. 定义要增加的StatusStrip
            StatusStrip sb = new StatusStrip();

            
//2. 定义StatusStrip项目中的控件,其中ToolStripLabel是一個相似於label的控件,現在用於顯示文字
            ToolStripLabel tsl = new ToolStripLabel();
            
//要顯示的文字內容
            tsl.Text = "Test";

            
//3. 定义StatusStrip中要项目
            ToolStripItem[] tsi = new ToolStripItem[1];
            tsi[
0= tsl;

            
//4. 將項目加入到StatusStrip中
            sb.Items.AddRange(tsi);

            
//5. 将StatusStrip加入到窗体中
            this.Controls.Add(sb);

            
#endregion
        }

結果:

原文地址:https://www.cnblogs.com/scottckt/p/969448.html