2016-03-08 107 views
1

我有一个窗体上的工具条的控制和编程方式使用下面的代码如何在C#中获取所选toolstripbutton指数

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

现在即时通讯试图让工具条的索引按钮添加到工具条控制按钮,当我点击它 注意到我能得到的点击文本toolstripbutton使用

e.ClickedItem.Text; 

回答

0

没有对索引属性ToolStripItem的点击,但你可以做这样的事情

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

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