添加ContextMenuStrip项(ToolStripItem)

前端之家收集整理的这篇文章主要介绍了添加ContextMenuStrip项(ToolStripItem)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

动态添加ContextMenuStrip项(ToolStripItem)

     
     
// 绑定菜单
private void BindMenu(DataTable dt)
{
foreach (DataRow row in dt.Rows)
{
ToolStripItem item
= new ToolStripMenuItem();
item.Name
row[ 0 ].ToString();
item.Text
1 ].ToString();
item.Click
+= EventHandler(contextMenuStrip1_ItemClick);
contextMenuStrip1.Items.Add(item);
contextMenuStrip1.Items.Add(row[1].ToString(),null,contextMenuStrip1_ItemClick); }
}

contextMenuStrip1_ItemClick( object sender,EventArgs e)
{
ToolStripItem item
(ToolStripItem)sender; MessageBox.Show(item.Name); }

猜你在找的VB相关文章