溫馨提示×

c# statusstrip怎樣顯示圖標文本

c#
小樊
113
2024-11-27 00:50:33
欄目: 編程語言

在C#中,要在StatusStrip控件中顯示圖標和文本,您需要創建一個ToolStripItem(例如ToolStripLabel或ToolStripButton),并將其Icon屬性設置為所需的圖標,Text屬性設置為所需的文本。以下是一個簡單的示例,說明如何在StatusStrip中添加一個帶有圖標和文本的ToolStripLabel:

using System;
using System.Windows.Forms;

namespace StatusStripExample
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            // 創建一個新的ToolStripLabel
            ToolStripLabel statusLabel = new ToolStripLabel();

            // 設置圖標(請確保將路徑替換為實際的圖標文件路徑)
            statusLabel.Icon = new System.Drawing.Icon("path/to/your/icon.ico");

            // 設置文本
            statusLabel.Text = "Status: Ready";

            // 將ToolStripLabel添加到StatusStrip
            statusStrip1.Items.Add(statusLabel);
        }
    }
}

在這個示例中,我們創建了一個名為statusLabel的ToolStripLabel,設置了其Icon屬性為一個圖標文件,并設置了Text屬性為"Status: Ready"。然后,我們將這個ToolStripLabel添加到了StatusStrip控件的Items集合中。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女