?
Solved

Windows Forms Application Losing focus

Posted on 2009-06-30
3
Medium Priority
?
852 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

764 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