winForm中获取UserControl的父容器的方法
我在WinForm(上面有个按钮)中加载用户自定义控件(上面有个ComboBox)之后,我希望能根据ComboBox的SelectedIndexChange中改变窗体上按...
我在WinForm(上面有个按钮)中加载用户自定义控件(上面有个ComboBox)之后,我希望能根据ComboBox的SelectedIndexChange中改变窗体上按钮的Enable属性,但是我不知道怎样获取到加载了用户控件的WinForm.希望哪位大哥大姐不吝赐教!!!
WinForm上包含Button和UserControl
UserControl里面装载了ComboBox 展开
WinForm上包含Button和UserControl
UserControl里面装载了ComboBox 展开
2个回答
展开全部
Form1上面加了ComboBox?然后在Form1上的button1的话直接用this.button1,Enable = false;
UserControl1中
//设为公有,然后在Form1中就可以访问这个ComboBox了
public System.Windows.Forms.ComboBox comboBox1;
Form1中订阅这三个事件都可以实现你想要的---
private void userControl11_Load(object sender, EventArgs e)
{
this.userControl11.comboBox1.SelectedValueChanged += new EventHandler(comboBox1_SelectedValueChanged);
this.userControl11.comboBox1.TextChanged += new EventHandler(comboBox1_TextChanged);
this.userControl11.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
void comboBox1_TextChanged(object sender, EventArgs e)
{
}
void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
}
UserControl1中
//设为公有,然后在Form1中就可以访问这个ComboBox了
public System.Windows.Forms.ComboBox comboBox1;
Form1中订阅这三个事件都可以实现你想要的---
private void userControl11_Load(object sender, EventArgs e)
{
this.userControl11.comboBox1.SelectedValueChanged += new EventHandler(comboBox1_SelectedValueChanged);
this.userControl11.comboBox1.TextChanged += new EventHandler(comboBox1_TextChanged);
this.userControl11.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
void comboBox1_TextChanged(object sender, EventArgs e)
{
}
void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询