c#自定义控件带参数事件 如何给a_SelectedIndexChanged传入i的值。代码如下
ComboBox[]a=newComboBox[10];publicstaticinti=0;privatevoidbutton1_Click(objectsender,...
ComboBox[] a = new ComboBox[10];
public static int i = 0;
private void button1_Click(object sender, EventArgs e)
{
a[i] = new ComboBox();
a[i].SelectedIndexChanged += new EventHandler(a_SelectedIndexChanged);
i+=1
}
private void a_SelectedIndexChanged(object sender, EventArgs e)
{
在这里取得i的值
} 展开
public static int i = 0;
private void button1_Click(object sender, EventArgs e)
{
a[i] = new ComboBox();
a[i].SelectedIndexChanged += new EventHandler(a_SelectedIndexChanged);
i+=1
}
private void a_SelectedIndexChanged(object sender, EventArgs e)
{
在这里取得i的值
} 展开
展开全部
多传一次
private void a_SelectedIndexChanged(object sender, EventArgs e)
这个方法的默认参数sender 就是指这个combox下拉菜单控件
在button1——click事件里面写上
a[i].Name=i.ToString()或者a[i].tag=i;
然后SelectedIndexChanged时间里面取出来
即
private void a_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox temp=(ComboBox)sender;
MessageBox.Show(temp.Name);//这个name就是前面存进去的值
}
private void a_SelectedIndexChanged(object sender, EventArgs e)
这个方法的默认参数sender 就是指这个combox下拉菜单控件
在button1——click事件里面写上
a[i].Name=i.ToString()或者a[i].tag=i;
然后SelectedIndexChanged时间里面取出来
即
private void a_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox temp=(ComboBox)sender;
MessageBox.Show(temp.Name);//这个name就是前面存进去的值
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询