Solved

Windows Forms Application Losing focus

Posted on 2009-06-30
3
817 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
Comment Utility
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
Comment Utility
Hi, Try this :
Me.Activate()

After your code

Good Luck
0
 

Accepted Solution

by:
mhw8 earned 0 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now