tags:

views:

1318

answers:

3

Hi
I have a bunch of controls (textbox and combobox) on a form with toolstripcontainer and toolstripbuttons for save, cancel etc for edits. We are using .Net 3.5 SP1
There is bunch of logic written in control.lostfocus and control.leave events. These events are not being called when clicked on the toolstrip buttons. Is there a way to call these events manually when any of these buttons are pressed.

Thanks.
Kishore

[Edit]

This is how I solved the problem. Thanks Chris Marasti-Georg for the pointer. In the button click event I calling focus on the toolstrip instead of the button as the toolstripbutton does not have a focus event. We can access the toolstrip on which the button is placed using

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

-Kishore

+1  A: 

You can extend those controls and then call the OnLostFocus and OnLeave protected methods of the base class...

Will
+4  A: 

You could listen to the click events on the buttons, and in the handler call their focus method. That would (hopefully) cause the previously focused control to respond correctly. Add the following handler to each button's click event:

private void ButtonClick(object sender, EventArgs e) {
    if(sender != null) {
        sender.Focus();
    }
}
Chris Marasti-Georg
A: 

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

configurator