如题,在程序的运行过程中我会动态的在form中添加一些图标,生成图标的时候也顺便给其添加了右键菜单 PictureBox newpic = new PictureBox(); newpic.Name = m_dataframe.TagID; newpic.Size = new System.Drawing.Size(48, 48); newpic.Location = new System.Drawing.Point(posInfo[0], posInfo[1]); newpic.Image = (Image)TheOldManCareSystem.Properties.Resources.normalState; newpic.BackColor = Color.Transparent; //add context menu to do some operate of the mark newpic.ContextMenuStrip = this.markContextMenuStrip;在程序运行过程中我右击已经生成的图标,希望通过选项来改变图标使用的image我该如何在右键菜单的处理程序(下视函数)中找到我点击的图标呢 private void alarmStateClear_Click(object sender, EventArgs e) { PictureBox picturebox = (PictureBox)sender; //picturebox.Image = (Image)TheOldManCareSystem.Properties.Resources.normalState; }上面操作sender是想当然的写的,错误。应该如何去获得控件的操作权
1 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
private void alarmStateClear(object sender, EventArgs e)
{
PictureBox picturebox = this.markContextMenuStrip.SourceControl as PictureBox;
if (picturebox != null)
{
//这里就可以处理你的PictureBox了
}
}
- 1 回答
- 0 关注
- 275 浏览
添加回答
举报
0/150
提交
取消