如何在c#中获取toolstripbutton的选定索引

时间:2016-03-08 15:03:09

标签: c# toolstripmenu

我在表单上有一个工具条控件,我使用下面的代码以编程方式将按钮添加到工具栏控件

            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);

现在,当我点击它时,我正试图获取工具条按钮的索引 请注意我可以使用

获取单击的工具条按钮的文本
e.ClickedItem.Text;

1 个答案:

答案 0 :(得分:1)

在tooltripitem点击上没有索引属性,但你可以这样做

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

Tag属性是您设置为索引的位置。