一、动态绑定右键菜单控件
///
/// 通过递归获取执行控件
///
///
///
///
private void actionSetContextMenuStrip
{
if (c is T)
{
if (acction != null)
{
acction((T)c);
}
}
else
{
foreach (Control item in c.Controls)
{
actionSetContextMenuStrip
}
}
}
二、调用
System.Windows.Forms.ContextMenuStrip cms2 = new System.Windows.Forms.ContextMenuStrip();
ToolStripMenuItem tsmiShowFixedValue = new ToolStripMenuItem() { Text = "查看默认标识的元素" };
tsmiShowFixedValue.BackColor = PublicColor.MyColorTeeL;
Action
//绑定右键菜单
actionSetContextMenuStrip
{
c.ContextMenuStrip = cms2;
});