1. How to make TextBox read only but look normal
- Posted by lockiedownunder Jul 06, 2009
- 1404 views
Gday to all,
At the moment in my program, when a record is in display mode I set the TextBox's to setEnabled(TXTBox,False) but this makes everything grey & looks yuk.
How might I better display the fields and prevent people from changing the contents. But then enable the fields after clicking the edit button.
Using win32lib of course.
Thanks Tony
2. Re: How to make TextBox read only but look normal
- Posted by DerekParnell (admin) Jul 06, 2009
- 1362 views
At the moment in my program, when a record is in display mode I set the TextBox's to setEnabled(TXTBox,False) but this makes everything grey & looks yuk.
How might I better display the fields and prevent people from changing the contents. But then enable the fields after clicking the edit button.
Firstly, the user interface needs to give the user a visual clue when a field is enabled or not. If you don't like the default disabled colours, you can set the background color for it. With the current win342lib in the sourceforge respository, you can call ...
setDisableBg( TXTBox, Brown) -- or any other color you like.
This is the background colour that the text control gets when it is disabled. By default, it is the Windows default backgrond, which is usually grey. If you don't like the foreground color, you can always set that when enabling/disabling it.
procedure enable_textbox(integer id, integer state) if state = False then setTextColor(id, BrightWhite) -- White text when disabled. else setTextCoor(id, Black) -- Black text when enabled. end if setEnable(id, state) end procedure
Then instead of using setEnable(TxtBox, False) use enable_textbox(TxtBox, False)
3. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 06, 2009
- 1335 views
Gday to all,
At the moment in my program, when a record is in display mode I set the TextBox's to setEnabled(TXTBox,False) but this makes everything grey & looks yuk.
How might I better display the fields and prevent people from changing the contents. But then enable the fields after clicking the edit button.
Using win32lib of course.
Thanks Tony
I thought the following would work, but it doesn't,
maybe someone can fix it or provide a different way that works?
-- code generated by Win32Lib IDE v1.0.4 Build July-06-2008 constant TheProgramType="exw" include Win32Lib.ew without warning -------------------------------------------------------------------------------- -- Window Window1 constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300, 0, 0 ) constant StatusBar5 = createEx( StatusBar, "StatusBar5", Window1, 0, 0, 0, 0, 0, 0 ) constant EditText3 = create( EditText, "EditText3", Window1, 16, 56, 140, 20, ES_READONLY ) constant PushButton4 = createEx( PushButton, "Enable Edit", Window1, 40, 24, 88, 28, 0, 0 ) --------------------------------------------------------- -------------------------------------------------------------------------------- procedure PushButton4_onClick (integer self, integer event, sequence params)--params is () sequence lflags1, lflags2 lflags1 = getStyleFlags(EditText3) removeStyle(EditText3, ES_READONLY ) -- only important part, rest is debug lflags2 = getStyleFlags(EditText3) setText(StatusBar5, sprint(lflags1) & " " & sprint(lflags2) ) end procedure setHandler( PushButton4, w32HClick, routine_id("PushButton4_onClick")) --------------------------------------------------------- WinMain( Window1,Normal )
4. Re: How to make TextBox read only but look normal
- Posted by ghaberek (admin) Jul 06, 2009
- 1374 views
If you use setEnable(), then you have to adjust the background color afterwards...
setWindowBackColor( ctrl, getSysColor(COLOR_WINDOW) )
You could wrap it into one whole function...
global procedure setEnable2( integer edit, integer state ) setEnable( edit, state ) setWindowBackColor( edit, getSysColor(COLOR_WINDOW) ) end procedure
-Greg
5. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 06, 2009
- 1353 views
wouldn't removeStyle be a more "direct" approach? (if it worked!)
since the idea is to make the edit control either be editable or not, making it "readonly" or not readonly would seem to be reasonable, if it worked, though it didn't in my test.
dan
6. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1370 views
I think the easiest way is to put in handlers for the text box for w32HkeyDown and w32HkeyPress, and in both cases call returnValue(w32True) to tell Win32Lib not to pass on keypresses, whether control keys or printable keys, onto the text box itself. I don't have the time to test this but IMHO it should work OK.
Andy
7. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 06, 2009
- 1404 views
I think the easiest way is to put in handlers for the text box for w32HkeyDown and w32HkeyPress, and in both cases call returnValue(w32True) to tell Win32Lib not to pass on keypresses, whether control keys or printable keys, onto the text box itself. I don't have the time to test this but IMHO it should work OK.
Andy
but in this method, couldn't app user still PASTE into the text box?
dan
8. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1349 views
but in this method, couldn't app user still PASTE into the text box?
dan
You're probably right. I wasn't thinking that way. I'm not sure how you could intercept this process; maybe w32HChange would be a better one. I'm not sure if it would be called prior to the change being executed. I suppose I shall have to try it myself now! Back later if I have any answers...
Andy
9. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1362 views
Yes, that is OK, Dan. I have an edit box with text in and I can't change it any way I can think of. Maybe the w32HChange is the only control necessary to intercept. but with those three doing a returnValue(w32True) it was just as you ask...
Andy
10. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 06, 2009
- 1311 views
but in this method, couldn't app user still PASTE into the text box?
dan
You're probably right. I wasn't thinking that way. I'm not sure how you could intercept this process; maybe w32HChange would be a better one. I'm not sure if it would be called prior to the change being executed. I suppose I shall have to try it myself now! Back later if I have any answers...
Andy
That's why I thought it would be best to just initially make the edit text a "read only", and then use "removeStyle(EditId,ES_READONLY) to allow editing. Only problem (!) is that it doesn't seem to work, though I can't see why not.
dan
11. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1338 views
That's why I thought it would be best to just initially make the edit text a "read only", and then use "removeStyle(EditId,ES_READONLY) to allow editing. Only problem (!) is that it doesn't seem to work, though I can't see why not.
dan
Yes, I can see that looks OK. Also I find that right-button and Paste still tramples on the text. I'll play some more but I can't see why it should. This task should be easier that it seems to be!
Andy
12. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1320 views
OK, this works. If you have a flag - I called it ROflag - which is True to make the control RO, and false to allow RW. You intercept the w32HEvent flag, and you test ROflag. If true do a returnValue(). This stops everything. But that includes painting. So you would need to leave ROflag false until the control is painted, setting it again afterwards to make the control inviolate.
You would probably be best to save the flag value in the main window onPaint handler, clearing it to allow the text to be painted, and restoring it after to the RO or RW state.
Does this make sense? It isn't terribly hygienic but it works. You can't do ANYTHING to the text box if the w32HEvent returnValue()'s.
Now we wait for Derek to tell us how it SHOULD be done...
Andy
13. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 06, 2009
- 1359 views
OK, this works. If you have a flag - I called it ROflag - which is True to make the control RO, and false to allow RW. You intercept the w32HEvent flag, and you test ROflag. If true do a returnValue(). This stops everything. But that includes painting. So you would need to leave ROflag false until the control is painted, setting it again afterwards to make the control inviolate.
You would probably be best to save the flag value in the main window onPaint handler, clearing it to allow the text to be painted, and restoring it after to the RO or RW state.
Does this make sense? It isn't terribly hygienic but it works. You can't do ANYTHING to the text box if the w32HEvent returnValue()'s.
Now we wait for Derek to tell us how it SHOULD be done...
Andy
. Does seem rather..Rube Goldberg!
Derek (and Greg) did earlier suggest to Tony to make the disabled edit more "presentable", by altering the background color of the disabled edit, which probably works just fine, I just thought that making the edit readonly and then altering that style as needed was a more elegant(?) approach, but then it didn't work, & I don't see why not.
Your way, though I guess it works, seems more like using an Elephant gun to shoot a mouse
Dan
14. Re: How to make TextBox read only but look normal
- Posted by AndyDrummond Jul 06, 2009
- 1380 views
Your way, though I guess it works, seems more like using an Elephant gun to shoot a mouse
Dan
True enough. I have a general principle. If I can't do it the "proper" way, I do it another way till I CAN do it. Mind you, quite often the "proper" way is more long-winded and cumbersome than the elephant gun approach!
I'll look forward to seeing if we do find this "proper" way, though .... and seeing if it IS easier!
Andy :)
15. Re: How to make TextBox read only but look normal
- Posted by Thomas Jul 06, 2009
- 1382 views
Your way, though I guess it works, seems more like using an Elephant gun to shoot a mouse
Dan
<snip>
I'll look forward to seeing if we do find this "proper" way, though .... and seeing if it IS easier!
Andy :)
Hi, Try this code.
integer set, ok set = 0 procedure PushButton4_onClick (integer self, integer event, sequence params) -- http://msdn.microsoft.com/en-us/library/bb761655%28VS.85%29.aspx ok = sendMessage(EditText3, EM_SETREADONLY, set, 0) set = not set end procedure setHandler( PushButton4, w32HClick, routine_id("PushButton4_onClick"))
16. Re: How to make TextBox read only but look normal
- Posted by DerekParnell (admin) Jul 06, 2009
- 1364 views
OK, this works. If you have a flag - I called it ROflag - which is True to make the control RO, and false to allow RW. You intercept the w32HEvent flag, and you test ROflag. If true do a returnValue(). This stops everything. But that includes painting. So you would need to leave ROflag false until the control is painted, setting it again afterwards to make the control inviolate.
You would probably be best to save the flag value in the main window onPaint handler, clearing it to allow the text to be painted, and restoring it after to the RO or RW state.
Does this make sense? It isn't terribly hygienic but it works. You can't do ANYTHING to the text box if the w32HEvent returnValue()'s.
Now we wait for Derek to tell us how it SHOULD be done...
Andy
. Does seem rather..Rube Goldberg!
Derek (and Greg) did earlier suggest to Tony to make the disabled edit more "presentable", by altering the background color of the disabled edit, which probably works just fine, I just thought that making the edit readonly and then altering that style as needed was a more elegant(?) approach, but then it didn't work, & I don't see why not.
Your way, though I guess it works, seems more like using an Elephant gun to shoot a mouse
Dan
I don't get it ... I already did say how it is to be done.
The user must have a visual clue that the field is not editable. You cannot just stop accepting events in the field because the user will not know that the program has changed state. You really have to show the user that the field is a no-go area. This GUI 101.
The simpliest way is to use setEnable(..., 0) and have the background colour change from the normal input scheme. That is why I suggest that during the program's form creation step, it should call setDisableBg() to set which colour to show when it's been disabled. That is all that has to be done! No fancy footwork or behind ther scenes redirecting of events.
There are many ways you can give visual hints that the field is disabled, but this is by far the easiest. I also suggested that one can change the colour of the text itself, but you could change the font/border/whatever..., but you have to do something.
Any field that looks like an input field should be editable. If it's not editable then it should not look like an input field.
17. Re: How to make TextBox read only but look normal
- Posted by bernie Jul 06, 2009
- 1351 views
The user must have a visual clue that the field is not editable. You cannot just stop accepting events in the field because the user will not know that the program has changed state. You really have to show the user that the field is a no-go area. This GUI 101.
The simpliest way is to use setEnable(..., 0) and have the background colour change from the normal input scheme. That is why I suggest that during the program's form creation step, it should call setDisableBg() to set which colour to show when it's been disabled. That is all that has to be done! No fancy footwork or behind ther scenes redirecting of events.
There are many ways you can give visual hints that the field is disabled, but this is by far the easiest. I also suggested that one can change the colour of the text itself, but you could change the font/border/whatever..., but you have to do something.
Any field that looks like an input field should be editable. If it's not editable then it should not look like an input field.
Derek: Couldn't they just setup a tooltip that would warn the user
when the users mouse hovers over the text box ?
18. Re: How to make TextBox read only but look normal
- Posted by DerekParnell (admin) Jul 06, 2009
- 1398 views
The user must have a visual clue that the field is not editable. You cannot just stop accepting events in the field because the user will not know that the program has changed state. You really have to show the user that the field is a no-go area. This GUI 101.
The simpliest way is to use setEnable(..., 0) and have the background colour change from the normal input scheme. That is why I suggest that during the program's form creation step, it should call setDisableBg() to set which colour to show when it's been disabled. That is all that has to be done! No fancy footwork or behind ther scenes redirecting of events.
There are many ways you can give visual hints that the field is disabled, but this is by far the easiest. I also suggested that one can change the colour of the text itself, but you could change the font/border/whatever..., but you have to do something.
Any field that looks like an input field should be editable. If it's not editable then it should not look like an input field.
Derek: Couldn't they just setup a tooltip that would warn the user
when the users mouse hovers over the text box ?
A good application does not rely on using a mouse. The user could attempt to use the TAB key to get to the field. If the cursor gets there and they can't type anything, then that is bad. If they can't TAB there but the field looks like an input field, then that is also bad.
No, there must be a visual clue that one can see just by looking at the form.
Can I recommend a book called "About Face" by Alan Cooper.
19. Re: How to make TextBox read only but look normal
- Posted by ArthurCrump Jul 06, 2009
- 1365 views
This reply is not concerned with the colours of an EditText box but only with the differences between the two principle methods suggested for setting READONLY.
Disabling the box using setEnable will result in a box which will not receive focus. It is not then possible to read from the box, so it cannot really be described as "Read Only".
sendMessage(EditText3,EM_SETREADONLY,True,0)
as suggested by Thomas results in a box which cannot be altered but which can receive focus. It is possible to select a section of input and read from it, but not to delete any of it or alter it.
The question is: Which behaviour do you want?
As for colours; they may be altered if required, I don't care.
20. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 07, 2009
- 1353 views
OK, this works. If you have a flag - I called it ROflag - which is True to make the control RO, and false to allow RW. You intercept the w32HEvent flag, and you test ROflag. If true do a returnValue(). This stops everything. But that includes painting. So you would need to leave ROflag false until the control is painted, setting it again afterwards to make the control inviolate.
You would probably be best to save the flag value in the main window onPaint handler, clearing it to allow the text to be painted, and restoring it after to the RO or RW state.
Does this make sense? It isn't terribly hygienic but it works. You can't do ANYTHING to the text box if the w32HEvent returnValue()'s.
Now we wait for Derek to tell us how it SHOULD be done...
Andy
. Does seem rather..Rube Goldberg!
Derek (and Greg) did earlier suggest to Tony to make the disabled edit more "presentable", by altering the background color of the disabled edit, which probably works just fine, I just thought that making the edit readonly and then altering that style as needed was a more elegant(?) approach, but then it didn't work, & I don't see why not.
Your way, though I guess it works, seems more like using an Elephant gun to shoot a mouse
Dan
I don't get it ... I already did say how it is to be done.
The user must have a visual clue that the field is not editable. You cannot just stop accepting events in the field because the user will not know that the program has changed state. You really have to show the user that the field is a no-go area. This GUI 101.
The simpliest way is to use setEnable(..., 0) and have the background colour change from the normal input scheme. That is why I suggest that during the program's form creation step, it should call setDisableBg() to set which colour to show when it's been disabled. That is all that has to be done! No fancy footwork or behind ther scenes redirecting of events.
There are many ways you can give visual hints that the field is disabled, but this is by far the easiest. I also suggested that one can change the colour of the text itself, but you could change the font/border/whatever..., but you have to do something.
Any field that looks like an input field should be editable. If it's not editable then it should not look like an input field.
Derek,
I did, above, mention that you and Greg had suggested a way to make edit box either editable or not, though I didn't go into any detail, since you already did. Maybe you thought you were responding to Andy's post, rather than my response to his post?
In any event, I continued to post regarding the matter because the method I thought to suggest, namely altering the STYLE of the edit box between read only and editable, with removeStyle( id, style ), DIDN'T ACTUALLY WORK, and I couldn't see why not.
So, the code stub demoing its not working is posted in a previous post in this thread, and I'm wondering if I somehow used the procedure wrong, or if there's a bug in it.
Dan
21. Re: How to make TextBox read only but look normal
- Posted by ArthurCrump Jul 07, 2009
- 1342 views
Quoting just a little of Dan's last message:
"In any event, I continued to post regarding the matter because the method I thought to suggest, namely altering the STYLE of the edit box between read only and editable, with removeStyle( id, style ), DIDN'T ACTUALLY WORK, and I couldn't see why not." ... Dan
I have also tried removeStyle and found that it doesn't work. However, several posts ago, Thomas indicated how the style could be removed. I have tried this and it DOES WORK. I repeat:
w32VOID = sendMessage(Ebox,EM_SETREADONLY,True,0)
When the Edit box is READONLY, it can receive focus and a portion may be selected even though the contents cannot be changed.
If you prefer it to be genuinely disabled and unable to receive focus, have you tried putting it in a Group control and disabling the Group control instead of the Edit box?
22. Re: How to make TextBox read only but look normal
- Posted by Dan_M Jul 07, 2009
- 1435 views
Quoting just a little of Dan's last message:
"In any event, I continued to post regarding the matter because the method I thought to suggest, namely altering the STYLE of the edit box between read only and editable, with removeStyle( id, style ), DIDN'T ACTUALLY WORK, and I couldn't see why not." ... Dan
I have also tried removeStyle and found that it doesn't work. However, several posts ago, Thomas indicated how the style could be removed. I have tried this and it DOES WORK. I repeat:
w32VOID = sendMessage(Ebox,EM_SETREADONLY,True,0)
When the Edit box is READONLY, it can receive focus and a portion may be selected even though the contents cannot be changed.
If you prefer it to be genuinely disabled and unable to receive focus, have you tried putting it in a Group control and disabling the Group control instead of the Edit box?
Thanks Arthur! Sorry I didn't notice Thomas' post showing how to remove the readonly style.
I think it's also possible to set readonly per your suggestion, AND make unable to receive focus, for tabbing only to fields which are supposed to be editable, by making an event for the readonly edit box, onGotFocus, & reseting focus to the NEXT appropriate field?
Dan