Solved

Windows Forms Application Losing focus

Posted on 2009-06-30
3
825 Views
Last Modified: 2012-05-07
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.

thanks,

-Mark
0
Comment
Question by:mhw8
3 Comments
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 24752333
After understaing your problem, I seems that your application is trying to fucus the control which is already hidden. and this is happening when you are trying to switch between user controls/panels on RH Panel.
I wll suggest you to make a focus after you get loading the panel/usercontrol by marking it as focus.

after making focus check for the property callled Focused.

I hope this will make sense for your application, if not can you please attach the sample app to us.
0
 
LVL 12

Expert Comment

by:Ammar Gaffar
ID: 24754412
Hi, Try this :
Me.Activate()

After your code

Good Luck
0
 

Accepted Solution

by:
mhw8 earned 0 total points
ID: 24757597
Rahu and Africans,

Thank you both for the suggestions. I have tried both and unfortunately found that they have no affect. I have tried adding focus, select and activate statements everywhere I can think of, but no luck.

It really seems that this issue is something specific to the tree control, since the problem goes away when I bypass it.

Any other areas to probe?

-Mark
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question