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
source to share
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();
}
}
source to share