如何在C#窗体中更改状态之前停止复选框事件触发? [英] How to stop check box event firing before changing state in C# windows form?

查看:68
本文介绍了如何在C#窗体中更改状态之前停止复选框事件触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



检查复选框有时会工作,有些时间不合适?

我发现即使我检查了复选框仍然它的属性是假的。我该如何解决这个问题?



我的尝试:



Hi,
when checking check boxes some times it working and some time not appropriately?
I found that even i checked the checkbox still it's property is false . How can i fix this?

What I have tried:

private void checkPOD_CheckedChanged(object sender, EventArgs e)
       {
           if (checkMobAd.Checked)
           {
               txtPOD1.ReadOnly = false;
           }
           else
           {
               txtPOD1.Clear();
               txtPOD1.ReadOnly = true;
           }
       }

推荐答案

在我看来你正在检查错误的控件。该事件附在checkPOD上,但你正在查看的复选框是checkMoAd。
It looks to me like you're checking the wrong control. The event is attached to checkPOD, but the checkbox you're looking at is checkMoAd.


我怀疑它每次都在工作:它肯定对我而言,我会成为如果这样的bug多年来一直没有引起注意,我感到很惊讶。

我怀疑它没有按照你的预期行事,因为它没有监视相同的复选框导致事件发生。尝试更改它以使用实际的CheckBox,看看会发生什么:

I'd suspect that it's working every time: it certainly does for me, and I'd be surprised if a bug like that had gone unnoticed for so many years.
I suspect that it just isn't doing what you expect because it's not monitoring the same checkbox as causes the event to fire. Try changing it to use the actual CheckBox and see what happens:
private void checkPOD_CheckedChanged(object sender, EventArgs e)
    {
    CheckBox cb = sender as CheckBox;
    if (cb != null)
        {
        if (cb.Checked)
            {
            txtPOD1.ReadOnly = false;
            }
        else
            {
            txtPOD1.Clear();
            txtPOD1.ReadOnly = true;
            }
        }
    }


这篇关于如何在C#窗体中更改状态之前停止复选框事件触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆