String Gadget - Read Only
-
- User
- Posts: 14
- Joined: Mon Aug 15, 2005 10:14 pm
- Location: Canada
String Gadget - Read Only
Forgive this question but how do I make a string gadget read only once it is created. I know it can be created as read only but 'read only' is an attribute I would like to turn off and on as determined by the business logic. I know also that I can disable gadgets but that makes the content invisible so is not quite what I am trying to achieve. I am trying to achieve a field where the user can enter text when I let them and read only (but still displaying the field data) otherwise. I'm sure it is simple but I can't seem to find anything in the help text or this forum. Thanks in advance.
Code: Select all
If OpenWindow(0,0,0,300,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Test") And CreateGadgetList(WindowID(0))
StringGadget(0,8, 10,200,20,"Some Text")
ButtonGadget(1,8, 40, 90, 20, "Change")
State.l = 0
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadgetID() = 1
State = 1 - State
SendMessage_(GadgetID(0), #EM_SETREADONLY, State, 0)
EndIf
EndSelect
ForEver
EndIf
{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}
-
- User
- Posts: 14
- Joined: Mon Aug 15, 2005 10:14 pm
- Location: Canada
Thanks HeX0R. That works. It's great. I sense I have a whole world of WINAPI's to explore .... somehow.
I had naively thought that this same command would apply to all gadgets but it seems only to work with string gadgets, which is after all what I asked for.
What do I change if I want this to also work for other gadgets (ComboBox, Checkbox, Editor, Option, Tree, etc)?
I had naively thought that this same command would apply to all gadgets but it seems only to work with string gadgets, which is after all what I asked for.
Code: Select all
#ReadOnly = 1
#Editable = 0
SendMessage_(GadgetID(#StringTopic), #EM_SETREADONLY, #ReadOnly, 0)
SendMessage_(GadgetID(#StringTopic), #EM_SETREADONLY, #Editable, 0)
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
No real need to use the WinAPI unless you want to.
Code: Select all
If OpenWindow(0,0,0,300,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 8, 10, 200, 20, "Some Text")
ButtonGadget(1, 8, 40, 90, 20, "Read Only")
ButtonGadget(2,110, 40, 90, 20, "Changeable")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadgetID() = 1
StringGadget(0,8, 10,200,20,GetGadgetText(0),#PB_String_ReadOnly)
EndIf
If EventGadgetID() = 2
StringGadget(0,8, 10,200,20,GetGadgetText(0))
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
-
- User
- Posts: 14
- Joined: Mon Aug 15, 2005 10:14 pm
- Location: Canada
Thanks Terry. That works well also. I modified it so that I don't have to remember the X and Y coords etc and it works just great.
I don't know which is best (API or PureBasic). API might be faster (maybe)while on the other hand there does seem something very pure about using only the PureBasic language where possible.
Regarding my followon question, I am reaching the conclusion that most other gadgets are not capable of read only mode but am still looking.
Code: Select all
StringGadget(0, GadgetX(0), GadgetY(0), GadgetWidth(0), GadgetHeight(0), GetGadgetText(0), #PB_String_ReadOnly)
Regarding my followon question, I am reaching the conclusion that most other gadgets are not capable of read only mode but am still looking.
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:

DisableGadget() is much simpler and faster.
Code: Select all
If OpenWindow(0,0,0,300,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 8, 10, 200, 20, "Some Text")
ButtonGadget(1, 8, 40, 90, 20, "Read Only")
ButtonGadget(2,110, 40, 90, 20, "Changeable")
DisableGadget(2,1)
OptionGadget(3, 8, 70, 150, 20, "Disallow text change?")
CheckBoxGadget(4, 8, 100, 100, 20, "Check my box")
SetGadgetState(4,1)
EditorGadget(5, 8, 130, 286, 64)
SetGadgetText(5,"Put some text in the editor gadget and see if it can be read.")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadgetID() = 1
DisableGadget (0,#TRUE)
DisableGadget (1,#TRUE)
DisableGadget (2,#FALSE)
SetGadgetState(3,#TRUE)
DisableGadget (3,#TRUE)
DisableGadget (4,#TRUE)
DisableGadget (5,#TRUE)
EndIf
If EventGadgetID() = 2
DisableGadget (0,#FALSE)
DisableGadget (1,#FALSE)
DisableGadget (2,#TRUE)
DisableGadget (3,#FALSE)
SetGadgetState(3,#FALSE)
DisableGadget (4,#FALSE)
DisableGadget (5,#FALSE)
EndIf
If EventGadgetID() = 3
If GetGadgetState(3) ; option is selected
DisableGadget(0,#TRUE)
DisableGadget(1,#TRUE)
DisableGadget(2,#FALSE)
DisableGadget(3,#TRUE)
DisableGadget(4,#TRUE)
DisableGadget(5,#TRUE)
Else
DisableGadget(0,#FALSE)
DisableGadget(1,#FALSE)
DisableGadget(2,#TRUE)
DisableGadget(3,#FALSE)
DisableGadget(4,#TRUE)
DisableGadget(5,#TRUE)
EndIf
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
checkbox gadget while selecting the Option doesn't even though the
code is identical. Hmm...
-
- User
- Posts: 14
- Joined: Mon Aug 15, 2005 10:14 pm
- Location: Canada
Darn. Looks like my brain must have turned to liquid and drained away again. I actually had a bug in my code which was giving me some results I didn't want. Can't believe it. Errr ... never happened before.
Anyway, thanks to everyones help I now have all that I need. In short, 'read only' mode works great for string gadgets with the added bonus that the user can place the mouse cursor on the text field to cut text for copying and can't change text. Perfect. Disablegadget does not, as I previously stated, make the field content disappear but does in fact display the field content and the user cannot place the mouse cursor or tab into that field. It also disables any type of gadget while displaying the content of that gadget. Also perfect. And finally, hidegadget does exactly what it says and hides the field. Between the three commands I can finally achieve what I was trying to get to so am very happy. Thanks to everyone for the help. I am really impressed with this forum and the level of activity in it.
Terry: Interesting anomoly with the checkbox gadget and I have no ideas. Well spotted. I suppose I can always save the value into a variable and set again after changing its state, just to be safe.
Anyway, thanks to everyones help I now have all that I need. In short, 'read only' mode works great for string gadgets with the added bonus that the user can place the mouse cursor on the text field to cut text for copying and can't change text. Perfect. Disablegadget does not, as I previously stated, make the field content disappear but does in fact display the field content and the user cannot place the mouse cursor or tab into that field. It also disables any type of gadget while displaying the content of that gadget. Also perfect. And finally, hidegadget does exactly what it says and hides the field. Between the three commands I can finally achieve what I was trying to get to so am very happy. Thanks to everyone for the help. I am really impressed with this forum and the level of activity in it.
Terry: Interesting anomoly with the checkbox gadget and I have no ideas. Well spotted. I suppose I can always save the value into a variable and set again after changing its state, just to be safe.