Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Resetting a control's focus upon windows regaining focus

Posted on 2005-03-31
Medium Priority
Last Modified: 2010-04-16

I just got a function which allows me to return the focus to a particular window, when I want to.  But the new problem is how do I record the control field which last had focus, so that I can return the focus to it?

I could come up with a hokey method where I retain an enumerated value, and each enumerated value relates to a particular control field.  But I'd like to see if there's a more elegant way, before I write it.

Does anybody have any idea about how to do this?

Thanks in advance.

Question by:ba272

Accepted Solution

AaronReams earned 2000 total points
ID: 13678292
Hi Bob,

This should all be handled for you automatically by windows.  This works for either inter-process or intra-process communication.  

You can test this by creating a simple form project and then creating two other forms.  Add a couple text boxes to each of the other forms and launch them modelessly (Show()).  You'll see as you switch back and forth (programatically by calling Form.Focus() or clicking with mouse) that the caret is in the textbox in each modeless form where you left it.

Something has probably gone awry in your app if focus is not maintained by the last control when you activate a form or process.  Are you perhaps forcing focus to another child control?

Hope this helps.


Author Comment

ID: 13678328
Thanks Aaron,

Actually, I was expecting it to be a problem and was circumventing the problem beforehand.  But come to think of it you're right.  Windows does that kind of work for me.
Problem solved.

That's a good thing to learn just before bed.

Good night.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

564 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