In C#, StatusStrip
the control is used to display the status bar at the bottom of the form, which is usually used to display the status information, progress, etc. of the application. StatusStrip
Provides an easy way to add and manage various controls on the status bar, such as labels, progress bars, buttons, etc. The following is StatusStrip
the detailed usage of the control:
-
Placing a control on a form
StatusStrip
:
In Visual Studio's Form Designer, drag and drop aStatusStrip
control from the toolbox to the bottom of your form. -
Add a status bar control:
- Use
StatusStrip.Items
the property to access the collection of status bar controls. - Use
ToolStripItem
a class derived from the class (egToolStripStatusLabel
,ToolStripProgressBar
) to create a status bar control. - Use
StatusStrip.Items.Add
the method to add controls toStatusStrip
the control. - Use the control's properties (eg
Text
, ,Value
etc.) to set its content and properties.
- Use
Here is an example showing how to use StatusStrip
the control:
using System;
using System.Windows.Forms;
namespace StatusStripExample
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
// 添加标签控件
ToolStripStatusLabel label1 = new ToolStripStatusLabel();
label1.Text = "状态栏标签1";
statusStrip1.Items.Add(label1);
// 添加进度条控件
ToolStripProgressBar progressBar1 = new ToolStripProgressBar();
progressBar1.Value = 50;
statusStrip1.Items.Add(progressBar1);
// 添加按钮控件
ToolStripButton button1 = new ToolStripButton();
button1.Text = "按钮";
button1.Click += Button1_Click;
statusStrip1.Items.Add(button1);
}
private void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("点击了按钮");
}
}
}
In the above example, we created a form application named "MainForm" and placed a StatusStrip
control. In the form's load event, we added a label control, a progress bar control, and a button control, and added a click event handler for the button control.
Hope this example can help you understand and use StatusStrip
the detailed method of the control. If you have any further questions, please feel free to ask!