C# 如何判断是哪个label元素打开的ContextMenuStrip

来源:百度知道 编辑:UC知道 时间:2024/05/24 02:31:59
程序中动态生成了若干个label,并且他们的ContextMenuStrip指向同一个ContextMenuStrip实例,如何判断是哪个label元素打开的ContextMenuStrip呢?

给你个动态生成batton的代码,
其实很简单,他们都是相通的

protected void Page_Load(object sender, EventArgs e)
{
Button button1 = new Button();
button1.Text = "自动添加到控件";
button1.ID = "button1";
button1.Click += new System.EventHandler(Button1_Click);
Form.Controls.Add(button1);

}

public void Button1_Click(object send, EventArgs e)
{
Response.Write("<script>alert('好像可以了欧耶!!!')</script>");

//大量自动生成button后获得点击button的值
Button button = send as Button;
Response.Write("<script>alert('"+button.ID.ToString()+"')</script>");

}

你看看通过ContextMenuStrip的opening事件的参数sender可不可以

实在不行设置一个公共字段