如何判断ContextMenuStrip打开后点击了哪个项
privatevoidToolStripMenuItem_Click(objectsender,EventArgse){PictureBoxp=(PictureBox)c...
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
PictureBox p = (PictureBox)contextMenuStrip1.SourceControl;
if (p.Tag==null)
{
foreach (Foliage f in farm.Shoppe.Foliages.Values)
{
if (f.Name.Equals(((ToolStripMenuItem)sender).Tag.ToString()))//报错报contextmenustrip 不能转成 toolstripMuneitme
{
p.Tag = f.Name;
Foliage foliage = new Foliage(f.Name, f.Maturate, f.MaturateAgain, f.Season, f.Image, f.BuyInPrice, f.Sellprice, f.NowSeason, f.RemnantTime, f.SoilName,"生长");
grow.Add(p.Name, foliage);
farm.Bag.BagFoliages[f.Name].FoliageCount--;
p.Image = f.Image;
}
}
}
} 展开
{
PictureBox p = (PictureBox)contextMenuStrip1.SourceControl;
if (p.Tag==null)
{
foreach (Foliage f in farm.Shoppe.Foliages.Values)
{
if (f.Name.Equals(((ToolStripMenuItem)sender).Tag.ToString()))//报错报contextmenustrip 不能转成 toolstripMuneitme
{
p.Tag = f.Name;
Foliage foliage = new Foliage(f.Name, f.Maturate, f.MaturateAgain, f.Season, f.Image, f.BuyInPrice, f.Sellprice, f.NowSeason, f.RemnantTime, f.SoilName,"生长");
grow.Add(p.Name, foliage);
farm.Bag.BagFoliages[f.Name].FoliageCount--;
p.Image = f.Image;
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询