Solved

Windows Forms Application Losing focus

Posted on 2009-06-30
3
820 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fso.FolderExists("\\server\HiddenFolder$") 4 49
Visual Studio 2015 Source Code Control 10 29
Vb. Net application freezes 9 30
Code works but it's slow 23 26
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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

15 Experts available now in Live!

Get 1:1 Help Now