winform中找某个控件的Tag属性,控件有可能是Button或ToolStripMenuItem,如果是ToolStripMenuItem时异常为

2024-12-16 07:02:12
推荐回答(1个)
回答1:

public int CheckJuri(object objFunc) //在调用此方法时用的sender
{
int isOk = 0;
string fc;
if (objFunc is Control)
{
Control con = (Control)objFunc; //错误如图
if (con.Tag == null) return -1;
}
else if (objFunc is ToolStripMenuItem)
{
ToolStripMenuItem con = (ToolStripMenuItem)objFunc; //错误如图
if (con.Tag == null) return -1;
}
}