选中另一个复选框时灰显一个复选框

Hel*_*rld 3 c#

基本上,我有一个交付复选框列表,一个用于传送到这个地址,另一个用于传送到一个单独的地址,我基本上想要这样做,所以一旦检查了另一个无法检出(可能是通过灰色或沿着这些路线的东西)

请注意,两个盒子都使用相同的控件.

Sim*_*Var 6

使用如下方法收听第一个CheckBox的CheckedChanged事件:

private void checkBox1_checkedChanged(object sender, EventArgs e)
{
    this.checkBox2.Enabled = !this.checkBox1.Checked;

    // If you want it to be unchecked as well as grayed out,
    // then have this code as well:
    if (!this.checkBox2.Enabled)
    {
        this.checkBox2.Checked = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是如果逻辑上符合您的需要,您应该考虑使用RadioButtons而不是CheckBoxes.