简体   繁体   English

检测是什么源更改了复选框的.Checked 属性 C# .NET WinForm

[英]Detect What Source Changed The .Checked Property of Checkbox C# .NET WinForm

I Used Win Form Design To Generate an event handler for checkbox to run some code when我使用 Win Form Design 为复选框生成事件处理程序以在以下情况下运行一些代码

checkbox.Checked == true 

. . Like This:像这样:

private void ckb_bootlockbit_app_read_CheckedChanged(object sender, EventArgs e)
        {
            if(ckb_bootlockbit_app_read.Checked == true)
            {
                DialogResult dr = new DialogResult();
                dr = MessageBox.Show("After Apply This Lock You Wont Be Able To Read Or Verify Flash Section ! \nAre You Want To Continue ?", "Warning", MessageBoxButtons.YesNo);
                if (dr == DialogResult.No) ckb_bootlockbit_app_read.Checked = false;
            }
        }

but there is One problem.但有一个问题。 I Also created a Button to run some code and change to.Enabled and.Checked of checkbox automatically, but I do not want that CheckedChanged function to run, just run when I click on checkbox and change its state. I googled and saw this for button clicked event:我还创建了一个按钮来运行一些代码并自动更改为.Enabled 和.Checked 复选框,但我不希望 CheckedChanged function 运行,只需在我单击复选框并更改其 state 时运行。我用谷歌搜索并看到了这个按钮点击事件:

(sender is Button button)

Is there a way to use that trick for CheckBox too?有没有办法对 CheckBox 也使用这个技巧?

Just Replaced CheckedChanged With Click And Worked.只需将 CheckedChanged 替换为 Click 即可。 Thanks to Ann L.感谢 Ann L。

private void ckb_bootlockbit_app_read_Click(object sender, EventArgs e)
    {
        if (ckb_bootlockbit_app_read.Checked == true)
        {
            DialogResult dr = new DialogResult();
            dr = MessageBox.Show("After Apply This Lock You Wont Be Able To Read Or Verify Flash Section ! \nAre You Want To Continue ?", "Warning", MessageBoxButtons.YesNo);
            if (dr == DialogResult.No) ckb_bootlockbit_app_read.Checked = false;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM