Hi, I'm trying to get the ID of a form control that has the current focus. It seemed to me the AddEvent in combination with the Sender function would do the trick, but it doesn't seem to work when I try the example in the help.
Here's the code:
Sub App_Start
AddEvent("cbShipName", Click, "FieldGotFocus")
End Sub
FieldGotFocus
Msgbox(Sender)
End Sub
Anyone have any ideas? Do I have to add a library or something like that?
Which type of controls do you have on your form?
For controls that support the GotFocus event you can use something like:
B4X:
Sub Globals
'Declare the global variables here.
End Sub
Sub App_Start
Form1.Show
AddEvent("TextBox1",GotFocus,"GotFocus")
AddEvent("TextBox2",GotFocus,"GotFocus")
AddEvent("TextBox3",GotFocus,"GotFocus")
End Sub
Sub GotFocus
form1.Text = Sender
Sender.Color = cGreen
End Sub
Hi Erel, thanks, that works perfectly, it's just what I needed.
But, I'm wondering why it doesn't work when I use the event Click instead of GotFocus? When I run it on the desktop and click the field, there's no response ...
Also, is there a list of the different event types somewhere?
Ok, thanks to you both, I get it. I was using a control that doesn't support the Click event - now I understand where to see the list of supported events for each control.