Keeping the cursor in an CEdit box
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Keeping the cursor in an CEdit box

  1. #1
    Join Date
    Sep 1999
    Location
    Salisburyl UK
    Posts
    324

    Keeping the cursor in an CEdit box

    Hi All..

    I have a simple dialog app which has 1 single line edit box and a couple of buttons on it.
    Id like to place the cursor in it when the app opens, but most importantly, the edit box shouldn’t loose the cursor, even it the user clicks a 'reset' button. The idea being that whenever the user starts to type, the cursor will be in the edit box.

    Your help would be very appreciated.

    Cheers
    Phill

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,878

    Re: Keeping the cursor in an CEdit box

    Use SetFocus() in the OnInitDialog()
    Be sure to return false from the dialog or it won't work.

    In the on-click handler for the reset button (and any other buttons), set the focus back to the editcontrol also.


    You could force the editcontrol to always have focus by overriding the OnSetFocus() and generically reforcing focus to the editcontrol, but this will mean normal tab-behaviour will fail. A user won't be able to tab to the reset button to 'click' it that way in case they have no mouse (or prefer not to use a mouse).

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Keeping the cursor in an CEdit box

    You can use the idea described by Reubens. But you should not code such that Edit control "always" have focus. That is bad design!

    You should reset all controls, when user clicks on 'Reset' and then set focus on this edit control. But user should be allowed to move between controls.

    And for dialog box, you should go to resource editor and set the tab arrangement. Just press Ctrl+D to set the arrangement.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  4. #4
    Join Date
    Sep 1999
    Location
    Salisburyl UK
    Posts
    324

    Re: Keeping the cursor in an CEdit box

    Thanks Ajay..
    I'll bare it in mind.

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Keeping the cursor in an CEdit box

    Quote Originally Posted by Phill Heald View Post
    Thanks Ajay..
    I'll bare it in mind.
    Did you mean bear?
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center