Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which control has focus on a form in VB6? 2

Status
Not open for further replies.

docrosen

Programmer
Jan 19, 2003
2
0
0
US
Is there a way to capture in code, using VB6, which control on the form currently has focus?
 
Docrosen,
This assigns the name property of the control to a label

Label1.Caption = Me.ActiveControl.Name

Michael
 
the most basic way is to use the GotFocus of the controls..

Declare a module level variable which where you will store the name of the control.

Set the name of the control in this variable in GotFocus event of all the controls.

Use this variable to know which control has the focus

Ex.

Private mCtlName as string

Private Sub Command1_GotFocus()
mCtlName = Command1.Name
End Sub

Private Sub Command2_GotFocus()
mCtlName = Command2.Name
End Sub

Private Sub Text1_GotFocus()
mCtlName = Text1.Name
End Sub

Private Sub Form_Unload(Cancel As Integer)
MsgBox mctlName & " has the focus."
End Sub


Hope this solve your problem... [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top