I am writing a windows forms application in vb.net and am having an issue with my window losing focus.
The application has two "frames"/panels. The left contains a tree control and the right contains a panel with a series of child controls. Selections in the LH tree control trigger the RH panel to be replaced with a new panel with another set of controls.
The application is behaving as I expect with the exception that the main window loses focus after the RH panel has been updated with a new panel. It is still the top window on the screen, but the title bar has lost focus and the tab key will not navigate to the various controls in the RH panel as it does when the window does have focus.
If I trigger the same "panel switching" logic from a control in the RH panel, rather than from the LH tree control, the window retains focus and all is well.
I have tried several methods to bring the window back into focus programatically (like using the user32 api with SetActiveWindow), but it seems to have no affect. I have also tried to explicitly set focus to a control in the RH panel, but again it has no affect.
If I intercept the mouse_leave event of the tree control and attempt to use the form's AcitveControl property by setting it to the tree or any other control, it throws an exception that hidden or disabled controls cannot be set as active.
I know it is a long shot, but perhaps someone can give me some ideas of things to look at to resolve this.