Capture name of control that has focus

Discussion in 'Questions (Windows Mobile)' started by aerohost, Jun 21, 2008.

  1. aerohost

    aerohost Member Licensed User

    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?

    Tks, AB :sign0161:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which type of controls do you have on your form?
    For controls that support the GotFocus event you can use something like:
    Code:
    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
     
  3. aerohost

    aerohost Member Licensed User

    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?

    Thanks, Adrian
     
  4. agraham

    agraham Expert Licensed User

    Do the controls you are using actually support the Click event? Only a very few do!
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    The help description of each control contains the list of events.
     
  6. aerohost

    aerohost Member Licensed User

    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.

    Regards, AB
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice