This is a dumb beginner question, and I tried to search for an answer but wasn't sure what to search for.
I opened the Visual Designer and created a button that said "Click." I want my first program to do something (anything) when the user clicks on the button. I couldn't figure out how to associate the "Click" button with code I want to run. Where do I put this code?
What if, for example, I want another window to open with a message like "Hello, world" when someone clicks on my "Click" button.
Any suggestions on where to start?
Thanks,
Phil
Associating gadgets in Visual Designerh
- Fangbeast
- PureBasic Protozoa

- Posts: 4792
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Gidday, hope this helps
No question is ever dumb, just wish some of the replies weren't either. Lots of things I still don't know and people think I should so never reply. The below is just a quick example of what you wanted with a single button in a frame. When you click the button a message requester pops up to let you know it worked. I chose that as a simple event linked to the button. Maybe not the cleanest way to show a beginner but the code is small.
Let me know if it helps you. Regards, Fang
Let me know if it helps you. Regards, Fang
Code: Select all
; PureBasic Visual Designer v3.72
;- Window Constants
;
#MyWindow = 0
;- Gadget Constants
;
#ClickMe = 0
#ClickFrame = 1
;----------------------------
; Procedure To generate a window And gadgets
;----------------------------
Procedure Open_MyWindow()
If OpenWindow(#MyWindow, 216, 0, 135, 117, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Click test")
If CreateGadgetList(WindowID())
ButtonGadget(#ClickMe, 40, 40, 60, 30, "Click Here")
Frame3DGadget(#ClickFrame, 20, 20, 100, 70, "", #PB_Frame3D_Double)
EndIf
EndIf
EndProcedure
;----------------------------
; Open the program window
;----------------------------
If Open_MyWindow() ; Open the program window if you can
Repeat ; Repeat the event checking from this point
EventID = WaitWindowEvent() ; Which event happened in the window?
If EventId = #PB_EventGadget ; if the event was generated by a gadget such as a button, do the below
Select EventGadgetID() ; Store the event id in memory for comparison
Case #ClickMe ; Was your button pushed? If so, detect it and do something
MessageRequester("Hello", "Your button was clicked and detected" #PB_MessageRequester_Ok) ; Your event
EndSelect ; No more events to check
EndIf ; Don't check for any more gadget events
Until EventID = #PB_Event_CloseWindow ; Go around and do the whole event checking loop again until window closed
EndIf
End ; End of program
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
How did you start this application? Did you use Visual Designer to design the window with the button, and then modify/add to the code to make the button do something?
I don't know how much Visual Designer does. Is its purpose solely limited to generating the code to put gadgets on the screen, providing code which I edit and enhance? Or, can I specify (to Visual Designer) procedures to execute should someone click on the "click me" button?
Thanks,
Phil
I don't know how much Visual Designer does. Is its purpose solely limited to generating the code to put gadgets on the screen, providing code which I edit and enhance? Or, can I specify (to Visual Designer) procedures to execute should someone click on the "click me" button?
Thanks,
Phil
- Fangbeast
- PureBasic Protozoa

- Posts: 4792
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
====================================================
Visual designer generates only the code to create the windows and gadgets. You have to add the actual 'connection' to the gadgets themseleves.
The below code was done by visual designer after I put the button and the frame in using what constant names I picked then saved into the editor to add the rest.
====================================================
=====================================================
You have to write the code yourself like that below to detect and act on any gadget presses, this is strictly for the programmer to decide, the visual designer does not do any of that.
=====================================================
Sorry about not being very clear before
Visual designer generates only the code to create the windows and gadgets. You have to add the actual 'connection' to the gadgets themseleves.
The below code was done by visual designer after I put the button and the frame in using what constant names I picked then saved into the editor to add the rest.
====================================================
Code: Select all
#MyWindow = 0
#ClickMe = 0
#ClickFrame = 1
Procedure Open_MyWindow()
If OpenWindow(#MyWindow, 216, 0, 135, 117, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Click test")
If CreateGadgetList(WindowID())
ButtonGadget(#ClickMe, 40, 40, 60, 30, "Click Here")
Frame3DGadget(#ClickFrame, 20, 20, 100, 70, "", #PB_Frame3D_Double)
EndIf
EndIf
EndProcedure
You have to write the code yourself like that below to detect and act on any gadget presses, this is strictly for the programmer to decide, the visual designer does not do any of that.
=====================================================
Code: Select all
;----------------------------
; Open the program window
;----------------------------
If Open_MyWindow() ; Open the program window if you can
Repeat ; Repeat the event checking from this point
EventID = WaitWindowEvent() ; Which event happened in the window?
If EventId = #PB_EventGadget ; if the event was generated by a gadget such as a button, do the below
Select EventGadgetID() ; Store the event id in memory for comparison
Case #ClickMe ; Was your button pushed? If so, detect it and do something
MessageRequester("Hello", "Your button was clicked and detected" #PB_MessageRequester_Ok) ; Your event
EndSelect ; No more events to check
EndIf ; Don't check for any more gadget events
Until EventID = #PB_Event_CloseWindow ; Go around and do the whole event checking loop again until window closed
EndIf
End ; End of program
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Hi pthien,
Another alternative is to try out the PureVision designer.
http://www.reelmediaproductions.com/purevision
It is used by many PureBasic users who wish to design professional commercial applications and produces very nice "skeleton" code to get you started quickly.
Another alternative is to try out the PureVision designer.
http://www.reelmediaproductions.com/purevision
It is used by many PureBasic users who wish to design professional commercial applications and produces very nice "skeleton" code to get you started quickly.
Hi pthien,
Visit Andre's site and download his very complete CodeArchive.zip file and look for the 'PureDemo' program that's included in the package. You'll find many, many snippets to get you started.
http://www.purearea.net/pb/CodeArchiv/CodeArchiv.html
You can also go to Paul's site (above), become a member and download the PureDemo.zip program there.
Regards,
--blueb
Visit Andre's site and download his very complete CodeArchive.zip file and look for the 'PureDemo' program that's included in the package. You'll find many, many snippets to get you started.
http://www.purearea.net/pb/CodeArchiv/CodeArchiv.html
You can also go to Paul's site (above), become a member and download the PureDemo.zip program there.
Regards,
--blueb



