如何在c#中写代码实现点下button1后该button1被禁用,点下button2后button1恢复可以使用.

2024-12-26 06:27:14
推荐回答(4个)
回答1:

private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
}

private void button2_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
}

回答2:

你这不是送分吗

回答3:

送分

回答4:

禁用控件:
1.将控件隐藏:
在button1的click事件中将button1的可见性设为false
private void button1_Click(object sender, EventArgs e)
{
this.button1.visable= false;
}
然后再button2的click的事件中将button1的可见性设为true
private void button2_Click(object sender, EventArgs e)
{
this.button1.visable = ftrue;
}
2.任然显示控件,但不实现该控件的任何功能,也就是不启用该控件
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
}
在button2的click事件中启用button1
private void button2_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
}