Raise the LostFocus event manually

I have a group of controls (textbox and combobox) on a form with toolstripcontainer and toolstripbuttons to save, cancel, etc. for editing. We are using .Net 3.5 SP1
There is a bunch of logic written in the control.lostfocus and control.leave events. These events are not triggered when clicking on the toolbar buttons. Is there a way to trigger these events manually when any of these buttons are pressed.

Thank.
Kishore

[change]

This is how I solved the problem. Thanks to Chris Marasti-Georg for the pointer. In the button click event I am calling, it focuses on the toolbar instead of the button, since the toolbar does not have a focus event. We can access the toolbar where the button is located with

((ToolStripButton) sender) .Owner.Focus ()

-Kishore

+1


source to share


3 answers


You can listen for button click events and in the handler their focus method. This will (hopefully) cause the previously focused control to respond correctly. Add the following handler for each button click event:



private void ButtonClick(object sender, EventArgs e) {
    if(sender != null) {
        sender.Focus();
    }
}

      

+4


source


You can extend these controls and then call the OnLostFocus and OnLeave methods on the base class ...



+1


source


I would suggest moving the login to a method outside the event handler and calling that method ...

+1


source







All Articles