Spin Gadget (und ein Hinweiß für das Help-File

Share your advanced PureBasic knowledge/code with the community.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Spin Gadget (und ein Hinweiß für das Help-File

Post by GPI »

Das Spin-Gadget enthält ja sowohl ein Text als auch einen (unsichbaren) Wert und das macht die Handharbung etwas schwieriger. Das Beispiel in der deutsch Anleitung ist nicht so gut:
A) Eingaben in Text-Bereich werden ignoriert
B) Mich stört das zusätzliche eventwindow() gewaltig...

Hier meine Lösung

Code: Select all

If OpenWindow(0,0,0,140,70,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"SpinGadget") And CreateGadgetList(WindowID(0)) 
    SpinGadget     (0,20,20,100,25,0,1000) 
    SetGadgetState (0,5) : SetGadgetText(0,"5")   ; Anfangswert festlegen 
    Repeat 
      ev.l = WaitWindowEvent() 
      If ev=#pb_event_gadget
        If EventGadgetID() = 0 
          If GetGadgetState(0)<>Val(GetGadgetText(0)) ; hat sich was geändert?
            If EventType()=#pb_eventtype_change ; = Eingabe in Textfeld
              SetGadgetState(0,Val(GetGadgetText(0)))
            Else
              SetGadgetText(0,Str(GetGadgetState(0)))
            EndIf
          EndIf
        EndIf
      EndIf 
    Until ev.l = #PB_Event_CloseWindow 
  EndIf 
p.s.: Man muß nicht unbedingt die Ziffern in Text-Feld schreiben, man kann da auch zwischen verschieden Wörtern umschalten...
Thorsten
User
User
Posts: 28
Joined: Sun Apr 27, 2003 2:55 pm
Location: Germany
Contact:

Post by Thorsten »

Hey GPI :D Wrong forum? :wink:
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Ah, Yes, complete wrong forum.

OK: Here a little translation of the text above:
In the german manual is a example of a spin-gadget, but there are two problems:
a) the example don't react, when i write text in the textbox of the spin
b) it used a windowevent() to throw a message away.

My Example above, shoes how the spin-gadget can handle correct, so that the user can type a value in the text box and can use the arrow buttons.

GPI
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

Hey GPI, thanks for your suggestions. They are noticed, even when they are in german..... :lol: :lol: :lol:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

GPI,

Nice tip! It might be good to check if something other than a number is typed into the SpinGadget. That way, you can keep the value unchanged, instead of setting it to zero (Val() of a non-numeric = 0).

Thanks,
Eric
Post Reply