StatusStrip控件中添加toolStripSeparator分割器
效果如图所示:
若要实现如图所示的效果,必须在
StatusStrip
状态条控件的属性集合中添加
ToolStripSeparator
工具条分割器控件。但是C#控件工具箱中没有此控件。
要实现以上的步骤必须在窗体设计器中添加代码实现。
1. 声明工具条分割器对象。
2. 实例化ToolStripSeparator对象和属性设置。
3. 将toolStripSeparator1分割器和toolStripSeparator2分割器添加到statusStrip1工具条的集合中的子元素。
完整代码如下:
namespace 状态条添加分栏
{
partial class MainFrm
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//2. 实例化工具条分割器对象
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
//
//3. 设置toolStripSeparator1工具条分割器的属性(名字和大小)
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 23);
//
//4. 设置toolStripSeparator2工具条分割器的属性(名字和大小)
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 23);
//
// statusStrip1
//
//5. 将toolStripSeparator1分割器和toolStripSeparator2分割器添加到statusStrip1工具条的集合中
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.toolStripSeparator1, //分割器toolStripSeparator1
this.toolStripStatusLabel2,
this.toolStripSeparator2, //分割器toolStripSeparator2
this.toolStripStatusLabel3});
this.statusStrip1.Location = new System.Drawing.Point(0, 354);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(533, 23);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.AutoSize = false;
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(150, 18);
this.toolStripStatusLabel1.Text = "状态一";
//
// toolStripStatusLabel2
//
this.toolStripStatusLabel2.AutoSize = false;
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Size = new System.Drawing.Size(150, 18);
this.toolStripStatusLabel2.Text = "状态二";
//
// toolStripStatusLabel3
//
this.toolStripStatusLabel3.AutoSize = false;
this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";
this.toolStripStatusLabel3.Size = new System.Drawing.Size(150, 18);
this.toolStripStatusLabel3.Text = "状态三";
//
// MainFrm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(533, 377);
this.Controls.Add(this.statusStrip1);
this.Name = "MainFrm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "状态条添加分栏";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;
//1. 声明工具条分割器对象
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
}
}
程序运行效果如下图:
版权声明:本文为qq_37769473原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。