0

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

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

1 回答 1

1

工具条项单击上没有索引属性,但您可以执行以下操作

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

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

于 2016-03-08T15:11:58.813 回答