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

}

源: http://www.enet.com.cn/article/2007/1123/A20071123921488.shtml