How to lock an edit box?
-
Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
-
Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
-
Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
Either use the
ES_READONLY
style when you create it, or theEM_SETREADONLY
message (CEdit::SetReadOnly
if you use MFC) at any time after creatign the control
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen -
if you want to do this easily, you'll probably want to use CRichEditCtrl with the read only property enabled instead of CEdit
-
You can do that to an Edit, too...
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen -
doesn't setting read only on an Edit gray the box by default? If so, and I can remember it doing that, you'd have to subclass and override. That's why I suggested the rich edit instead.
yes it does - (I thought that would be ok with the asker) However, there's a message you can override in the dialog to proivde a different background brush. Peter
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen -
Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
As others have mentioned, you use the EM_SETREADONLY message. However, this will cause the edit box to be grayed out. You can still select the text, copy it, etc.. If you want the control to look like a normal edit control, but be read-only, then you need to catch WM_CONTROLCOLOR and look for the controls window handle and return a brush that's the same as the users color preferences. I'd advise against that, though. It confuses users when a control looks editable, but really isn't. -- Where are we going? And why am I in this handbasket?