CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: focus problem

  1. #1
    Join Date
    Nov 2000
    Location
    Tokyo and Memphis
    Posts
    238

    focus problem

    I have a mess of controls on my form.

    Using the arrow keys the focus passes from one command button to the next - fine. But then it disappears off the screen. Nothing has the focus.

    How can I check if nothing has the focus then give focus to command1.

    Cheers a lot

    Phil



  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: focus problem

    It doesn't happen that "nothing has the focus". Something has the focus, its only that it is not seen. For example, we do not see a picturebox having focus. Identify such elements and set their tabstop property to false. You can do it in one go during form load like

    dim aControl as Control
    for each aControl in Controls
    if TypeOf aControl is PictureBox then aControl.Tabstop = false
    next




    To identify which control has the focus, put a timer on your form, set its interval to 2 seconds, say, and in the timer event, write


    MsgBox ActiveControl.Name




    Now play with your keys. When the focus seems to disappear, wait some time and the name of the control with the focus will pop up.




  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: focus problem

    Something has the focus somewhere. Check the TabIndex property of the last control that gained and lost the focus. Then look for a control with a higher number. The control may be hidden behind another, Could be a menu item or a control that does not display the Focus rectangle.

    John G

  4. #4
    Join Date
    Nov 2000
    Location
    Tokyo and Memphis
    Posts
    238

    Re: focus problem

    Hmm - thanks guys.

    Yes, focus was being trapped by picture1. Once there, the arrow keys no longer switch focus though the tab key does.

    I can do something about that - no problem - thanks very much.

    Phil


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured