Solved

Windows Forms Application Losing focus

Posted on 2009-06-30
3
840 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

695 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