Click Event Not Firing - Cannot Change Focus - Cannot Close Form

前端 未结 3 1687
难免孤独
难免孤独 2020-12-06 13:11

I have a Windows Forms Application. I have several forms in this application (a main form, and several specialized forms), and on only one form, click events are not firing

相关标签:
3条回答
  • 2020-12-06 13:56

    Here is the reason:

    When using data binding, when you enter a value in a data bound control, it first tries to validate entry and then if the entry was valid, data binding will put the value in data source, but if a validation error occurs validation returns false and your control goes to invalid mode.

    When a child control of form didn't validate, by default you can not change focus from invalid control.

    Click on a button by default causes validation of the control that are losing the focus, so you can't click on button, as you see your button reflect to mouse but not actually click.

    The same problem will happen if you handle Validating event of a control like TextBox and set e.cancel = true.

    Here is the fix:

    you can fix this behavior using either of following options:

    • Set CausesValidation property of your button to false
    • Set AutoValidate property of your form to AutoValidate.EnableAllowFocusChange
    0 讨论(0)
  • 2020-12-06 13:56

    I have discovered the issue after further testing.

    I the issue is not with button events, but with the form becoming blocked after making a selection from a drop down box.

    I have not yet discovered why the form blocks after the drop down is selected (it has no events, but does have databinding, so there are some possible causes there).

    Thank you for all your help!

    0 讨论(0)
  • 2020-12-06 13:58

    This will do the trick for you

    Change

    public ScheduleMeeting()
    {
        InitializeComponent();
    } 
    

    to

    public MyForm()
    {
        InitializeComponent();
    }
    
    0 讨论(0)
提交回复
热议问题