identifying a pressed button
BlitzMax Forums/BlitzMax Beginners Area/identifying a pressed button
| ||
Hi Coders :-) How do I find which gadget, a button, was pressed? There is a yawning cavity where this knowledge should be :-/ Here's my code: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global xres:Int = GadgetWidth(Desktop:TGadget()) Global yres:Int = GadgetHeight(Desktop:TGadget()) Global px:Int = (xres/2) - 315 Global py:Int = (yres/2) - 55 Global window:TGadget=CreateWindow("Compare Files", px, py, 630, 109, Null, 3|WINDOW_ACCEPTFILES) Global file1:TGadget = CreateTextField:TGadget(0, 2, 620, 22, window) Global file2:TGadget = CreateTextField:TGadget(0, 28, 620, 22, window) Global button:TGadget = CreateButton:TGadget("OK", 0, 55, 620, 22, window, BUTTON_OK) Repeat WaitEvent() If EventID()=EVENT_WINDOWACCEPT If TextFieldText(file1)>"" SetGadgetText(file2, EventText()) Else SetGadgetText(file1, EventText()) EndIf EndIf If EventID()=EVENT_WINDOWCLOSE End SetGadgetText(file1, ButtonState(button)) Forever '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you run this yourself, you'll see that no matter how much I click the button, the ButtonState does not vary from zero. I obviously need to uniquely identify the button and I do not know how. Can anyone help, please? Julian ((*)(*)) |
| ||
Global xres:Int = GadgetWidth(Desktop:TGadget()) Global yres:Int = GadgetHeight(Desktop:TGadget()) Global px:Int = (xres/2) - 315 Global py:Int = (yres/2) - 55 Global window:TGadget=CreateWindow("Compare Files", px, py, 630, 109, Null, 3|WINDOW_ACCEPTFILES) Global file1:TGadget = CreateTextField:TGadget(0, 2, 620, 22, window) Global file2:TGadget = CreateTextField:TGadget(0, 28, 620, 22, window) Global button:TGadget = CreateButton:TGadget("OK", 0, 55, 620, 22, window, BUTTON_OK) Local Time:Int CreateTimer(60) Repeat WaitEvent() If EventID()=EVENT_WINDOWCLOSE End Select EventID() Case EVENT_GADGETACTION Select EventSource() Case Button SetGadgetText(file1, "OK Pressed") Time:Int = MilliSecs() 'only for showing the behaviour End Select Case EVENT_TImerTick If MilliSecs()-Time > 1000 Then SetGadgetText(file1, "No button Pressed") End Select Forever This should help you (the Timer things are only for demonstration. They are not needed) |
| ||
That worked! Thank you so much :-) Julian ((.)(.)) o0o0o0o0o0o0o0o0o0o |
| ||
Just in case you're not aware these are excellent. |