August 18th, 2003, 04:23 PM
How to prevent a control getting focus?
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.
August 18th, 2003, 04:48 PM
One solution is to allow it to gain focus, but then immediately defocus it and then set another control to focus.
August 18th, 2003, 05:25 PM
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.
August 18th, 2003, 08:09 PM
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.
August 19th, 2003, 12:31 AM
Re: How to prevent a control getting focus?
Well...simple and short answer...yes.
Originally posted by RichardScott
would I be better using a static control?
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.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!