我已经添加了一个菜单条控制器,并为这些菜单项添加了点击事件。
例如:
private void mnuaddTestingBuyersForFigures_Click(object sender, EventArgs e)
{
frmAddTestingBuyersForFigure obj = new frmAddTestingBuyersForFigure();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
private void mnuOperatorIncentive_Click(object sender, EventArgs e)
{
frmOperatorIncentive obj = new frmOperatorIncentive();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
private void mnuSetUpIncentiveMonthProcess_Click(object sender, EventArgs e)
{
frmSetUpWeeksForIncentiveMonth obj = new frmSetUpWeeksForIncentiveMonth();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
在这里,我想要来自另一个事件的点击上方的火事件。我只想把菜单条名称作为参数传递给方法,并激发它的相应事件
例如:
ShowMe("mnuSetUpIncentiveMonthProcess");
//Out put open the frmSetUpWeeksForIncentiveMonth form
ShowMe("mnuOperatorIncentive");
//Out put open the frmOperatorIncentive form
不使用条件语句
您可以通过名称找到控件,然后调用其PerformClick()
方法:
private void ShowMe(string name)
{
var item = (MenuStripItem)this.Controls[name];
item.PerformClick();
}