Detailed usage of statusStrip1 control in C#

In C#, StatusStripthe 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. StatusStripProvides an easy way to add and manage various controls on the status bar, such as labels, progress bars, buttons, etc. The following is StatusStripthe detailed usage of the control:

  1. Placing a control on a form StatusStrip:
    In Visual Studio's Form Designer, drag and drop a StatusStripcontrol from the toolbox to the bottom of your form.

  2. Add a status bar control:

    • Use StatusStrip.Itemsthe property to access the collection of status bar controls.
    • Use ToolStripItema class derived from the class (eg ToolStripStatusLabel, ToolStripProgressBar) to create a status bar control.
    • Use StatusStrip.Items.Addthe method to add controls to StatusStripthe control.
    • Use the control's properties (eg Text, , Valueetc.) to set its content and properties.

Here is an example showing how to use StatusStripthe 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 StatusStripcontrol. 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 StatusStripthe detailed method of the control. If you have any further questions, please feel free to ask!

Guess you like

Origin blog.csdn.net/xiaogongzhu001/article/details/131112124