- 1). Open your Visual Basic project.
- 2). Drag a "button" from the toolbox on the left into your project. This will serve as a hook for calling the code for finding the current focus. Later, you can remove it from your project and paste the code in the appropriate place for your needs.
- 3). Double-click the button to create a click event. This will automatically take you to the source code editor.
- 4). Paste the following for Visual Basic 6:
Debug.Print Screen.ActiveControl.name
This will print the name of the control that has focus to the debugging window whenever the button you created is clicked.
Alternatively, on later versions of Visual Basic, each individual form will have its own active control, so replace the above code with:
Debug.Print Form1.ActiveControl.name
Replace "Form1" with the name of the current form.
previous post