How to check if control has focus?

Discussion in 'Questions (Windows Mobile)' started by RB Smissaert, Jan 11, 2009.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    How do I check if a control (in this case I am interested in the Table control) has focus? Is the only way to keep track with LostFocus and GotFocus via global variables and deduct the Table focus from that?

    RBS
     
  2. Cableguy

    Cableguy Expert Licensed User

    The simplest way is to have a flag, lets call it "FocusedControl"...
    An in the "GotFocus" event add:

    CheckFocused


    Sub CheckFocused
    FocusedControl=sender.name
    'Do the checking you need done...

    End sub
     
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    I didn't know about the Sender object, but as the table control has no GotFocus event I have solved my problem know with GotFocus and LostFocus.
    The only relevant controls were 2 textboxes and a table control, so no problem there.

    RBS
     
  4. klaus

    klaus Expert Licensed User

    You can do it with the Door library.

    Attached an example.

    Best regards.
     

    Attached Files:

  5. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Thanks for the tip and I use the door library already to sort the table columns with a click on the headers and that works very nice. I noticed your code works with a timer and I am not keen to add that as I take it that there is some
    overhead. Can't the door library check focus of controls without a timer?

    RBS
     
  6. klaus

    klaus Expert Licensed User

    The timer was just to show the state changing, when clicking either onto the table or the button, and nothing else.
    You can check the Focused parameter where ever you want.

    Best regards.
     
    Last edited: Jan 11, 2009
  7. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Ah, of course, I got it now!
    Thanks again for the tip.

    RBS
     
  8. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    The Door method works nicely and quite simple, but I need to know the focus when I am clicking a menu item, so at that moment the table won't have focus.
    So, I still will need to stick with the old method (tracking the textboxes focus) unless there was an event such as BeforeMenuClick.

    RBS
     
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