PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Noble D. Bell on December 31, 2007, 02:26:10 AM

Title: Read-Only / Editable Toggle at Runtime For textbox control
Post by: Noble D. Bell on December 31, 2007, 02:26:10 AM
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?
Title: Re: Read-Only / Editable Toggle at Runtime For textbox control
Post by: Rudolf Fürstauer on December 31, 2007, 04:06:03 AM
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
Title: Re: Read-Only / Editable Toggle at Runtime For textbox control
Post by: TechSupport on December 31, 2007, 10:54:30 AM
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


Title: Re: Read-Only / Editable Toggle at Runtime For textbox control
Post by: Rudolf Fürstauer on December 31, 2007, 11:43:51 AM
Wow, that's really much easier  ;)


Happy new year to everyone!!!
Title: Re: Read-Only / Editable Toggle at Runtime For textbox control
Post by: Noble D. Bell on December 31, 2007, 10:54:33 PM
Wow! Impressive indeed!
Thanks.
nb