Read-Only / Editable Toggle at Runtime For textbox control

Started by Noble D. Bell, December 31, 2007, 02:26:10 AM

Previous topic - Next topic

Noble D. Bell

I hope this will be the last question I have to ask for awhile...

I know that you can set the ES_READONLY property in the Window Styles section to make a textbox read-only. What I want to do is, in code at runtime, make a textbox read only or editable via a function call. I don't want to use enable/disable because when you disable a control it makes the text grey as well.

Any thoughts?

Rudolf Fürstauer

There are two way's:
* set/unset the style via SetWindowLong %ES_READONLY
* Subclass the edit control, and when needed reject inputs


    'set style (do not allow user to change textbox contents)
    lStyle = GetWindowLong(GetDlgItem(CBHNDL, %ID_TEXTBOX), %GWL_STYLE)
    lStyle = (lStyle OR %ES_READONLY)
    SetWindowLong GetDlgItem(CBHNDL, %ID_TEXTBOX), %GWL_STYLE, lStyle
    '
    'unset style (allow user to change textbox contents)
    lStyle = GetWindowLong(GetDlgItem(CBHNDL, %ID_TEXTBOX), %GWL_STYLE)
    lStyle = (lStyle AND NOT %ES_READONLY)
    SetWindowLong GetDlgItem(CBHNDL, %ID_TEXTBOX), %GWL_STYLE, lStyle

TechSupport

Here is an even easier way:    :)


   SendMessage HWND_FORM1_TEXT1, %EM_SETREADONLY, %TRUE, 0


%TRUE sets the control to read only, %FALSE makes it editable.

Here is the link to the edit control styles:
http://msdn2.microsoft.com/en-us/library/bb775464.aspx



Rudolf Fürstauer

Wow, that's really much easier  ;)


Happy new year to everyone!!!

Noble D. Bell