How to prevent a control getting focus?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to prevent a control getting focus?

  1. #1
    Join Date
    Aug 2003
    Location
    Brighton England
    Posts
    1

    How to prevent a control getting focus?

    Hello,

    Is it possible to prevent a control from being selected? I'm using edit boxes to present text to the user but don't want them to be able to select the boxes..??

    Any ideas? would I be better using a static control?

    Thanks in advance.

    RichardScott.

  2. #2
    Join Date
    Feb 2002
    Posts
    5,758
    One solution is to allow it to gain focus, but then immediately defocus it and then set another control to focus.

    Kuphryn

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    Depends on what your objectives are:

    if you want to go with Static controls, fine.
    If not , read ....

    One way is you could EnableWindow(FALSE) on that control so that it will appear disabled. Then the user won't be able to tab into the control or use mouse to click on it so that it gains focus.You wouldn't even be able to SetFocus() programmatically.

    Also, you wouldn't annoy a user who would click on the edit control only to see the caret blinking somewhere else
    Again, in this approach you wouldn't need to keep track of to what to set focus to, should it be back to the one you got focus from or to someother control ?

    You may also want to take care of standard windows UI guidelines. I would get thoroughly irritated if UI guidelines are not followed.

    Just some ideas. U are the best judge for the situation.

    - Kiran

  4. #4
    By definition, disabled windows ignore all input messages. The query only speaks of "presenting" text to the user but not allowing the user to select, not necessarily to edit, the text. Is this literally your intended purpose? Then you should use a static control. If you want the user to copy the text, but not edit it, you can use an edit box with the ES_READONLY style. Using a disabled edit box is not recommended unless there is a chance that the user may be able to use it.

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to prevent a control getting focus?

    Originally posted by RichardScott
    would I be better using a static control?
    Well...simple and short answer...yes.

    As the name 'Edit Control' already implies...the content of the control can be edited (I know that you can set it read-only etc. but that is not the point here - GUI design guidelines...). If you simply want to display text which will not be changed by the user...simply use static text controls...
    Last edited by Andreas Masur; August 19th, 2003 at 12:33 AM.
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center