5

基本上,我有一个交付复选框列表,一个用于交付到该地址,另一个用于交付到单独的地址,我基本上想这样做,所以一旦一个被检查过,另一个就不能被签出(也许通过将其变灰或类似的东西)

请注意,两个框使用相同的控件。

4

2 回答 2

8

使用如下方法监听第一个 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;
    }
}

但是,如果它在逻辑上符合您的需求,您应该考虑使用 RadioButtons 而不是 CheckBoxes。

于 2012-06-14T12:26:56.787 回答
1

使用以下代码,

checkboxToBeGreyed.Enabled = false;

您已经在其他复选框的选中事件中编写了此代码。希望这可以帮助。

于 2012-06-14T12:26:40.003 回答