|
-
Sep 12th, 2002, 01:54 PM
#1
Thread Starter
Addicted Member
Control, Gotfocus
How can I see if a Control on the form gets the Focus (GotFocus) AND what Control that is (Control.name) ?
-
Sep 12th, 2002, 01:55 PM
#2
PowerPoster
Read help on ActiveControl.
-
Sep 12th, 2002, 01:57 PM
#3
Re: Control, Gotfocus
Originally posted by Kars Lensen
How can I see if a Control on the form gets the Focus (GotFocus) AND what Control that is (Control.name) ?
you could put code in the gotfocus event of the control you are working with..
-
Sep 12th, 2002, 02:02 PM
#4
PowerPoster
Well
Depending upon what you are trying to do, you can use this in a global sub...
I use it to change the backcolor of the control which receives focus...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 12th, 2002, 02:12 PM
#5
Thread Starter
Addicted Member
Thanks all, I now I can do it in the Gotfocus event but I wil do that only once in the form (or the project ...), James can you give an example ?
-
Sep 12th, 2002, 03:53 PM
#6
PowerPoster
Well
Very simple example :
VB Code:
' ON GOT FOCUS EVENT ON CERTAIN CONTROLS
Function YELLOWGOTFOCUS(GETCONTROL As Control)
On Error Resume Next
If TypeOf GETCONTROL Is TextBox Then
GETCONTROL.BackColor = vbYellow
GETCONTROL.ForeColor = vbRed
GETCONTROL.SelStart = 0
GETCONTROL.SelLength = Len(GETCONTROL)
ElseIf TypeOf GETCONTROL Is ComboBox Then
GETCONTROL.BackColor = vbYellow
GETCONTROL.ForeColor = vbRed
End If
End Function
' ON LOST FOCUS OF CERTAIN CONTROLS
Function WHITELOSTFOCUS(GETCONTROL As Control)
If TypeOf GETCONTROL Is TextBox Then
GETCONTROL.BackColor = vbWhite
GETCONTROL.ForeColor = vbBlack
ElseIf TypeOf GETCONTROL Is ComboBox Then
GETCONTROL.BackColor = vbWhite
GETCONTROL.ForeColor = vbBlack
End If
End Function
If you add this code to a module, you can access from anywhere inside your project...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|