簡體   English   中英

如何在C#中獲取toolstripbutton的選定索引

[英]How to get selected index of toolstripbutton in c#

我在窗體上有一個工具欄控件,並使用以下代碼以編程方式將按鈕添加到工具欄控件

            toolStrip1.Visible = true;
            ToolStripItem t = new ToolStripButton();
            t.Text = client.EndPoint.ToString();
            t.TextImageRelation = TextImageRelation.ImageAboveText;
            t.BackgroundImage = Image.FromFile("" + Application.StartupPath + "ps1_new.PNG");
            t.AutoSize = false;
            t.Height = 67;
            t.Width = 70;
            t.BackgroundImageLayout = ImageLayout.Stretch;
            t.TextAlign = ContentAlignment.BottomCenter;
            toolStrip1.Items.Add(t);

現在我試圖在我單擊它時獲得toolstrip按鈕的索引,請注意,我可以使用以下方法獲取被單擊的toolstripbutton的文本

e.ClickedItem.Text;

工具tripitem單擊上沒有索引屬性,但是您可以執行以下操作

    private void ToolStrip1_ItemClicked(object sender, EventArgs e)
    {
        MessageBox.Show(e.ClickedItem.Tag)
    }

Tag屬性是您設置為索引的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM