Text boxes and sliders
BlitzMax Forums/BlitzMax Beginners Area/Text boxes and sliders
| ||
| Hello!!! I want to associate sliders to text boxes and use special properties. We can use the sliders to select values between 0 and 255. How do I limit the number of characters in the text box to 3 digits and prevent non numeric characters? Here is how I am creating one of the sliders and associate a text box to it:
' Place the main panel which will have most of the gadgets inside
Global panel:TGadget=CreatePanel(21,97-4-2+8-6-3,450+20-20,240-20-20-20-40+6+3+2,window,PANEL_GROUP,"NORMAL TRAINER")
' SetGadgetLayout panel, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED
' SetGadgetColor(panel,160,255,160)
' Create sliders
' LIVES1
Global lives1_slider = CreateSlider:TGadget(80-10-2,10,20,20,panel:TGadget,SLIDER_STEPPER)
SetSliderRange(lives1_slider,0,255)
SetSliderValue(lives1_slider,lives1)
Global status_text_field_lives1=CreateTextField:TGadget(80-40-10,10+1,35,16+4,panel)
SetGadgetText(status_text_field_lives1,lives1)
CreateLabel("LIVES1",80-10-2+10+10+5,20-5-2,40,15,panel)
Any ideas? Thanks! Kind regards, >Marco A.G.Pinto ------------------- |
| ||
| you have two possibilities. first is to check it. 1. After the textbox is firing an event, because the user is pressing a key. This has tha advantage of checking characters and digits in the same function: Function Event (EventQuelle:Object) Local tmpGadget:TGadget = TGadget(EventQuelle) If tmpGadget If GadgetClass(tmpGadget) = GADGET_TEXTFIELD CheckInhalt 3, tmpGadget ..... Function CheckInhalt(Anzahl% , TextField:TGadget ) Local Zeichen$, i% , Erlaubt$ , Inhalt$ Inhalt=GadgetText(TextField) Inhalt=Upper(Inhalt) Erlaubt="1234567890" For i=1 To Len(Inhalt) zeichen=Mid(Inhalt,i,1) If Erlaubt.Find(Zeichen)=-1 Then PrintOut "verboten " + zeichen Inhalt=Left(Inhalt,i-1)+Mid(Inhalt,i+1,-1) EndIf Next Inhalt=Left(Inhalt,Anzahl) SetGadgetText TextField,Inhalt End Function 2. A second possibility is to use the build-in-pre-check of MaxGui.This only can check charakters, but you can add a digit checking too: This adds a callback function to the maxgui, which is called erery time when a key is pressed in this textgadget. Depending on the RETURN-vakue of the function MaxGui add the new character or not: You need to let through also the BACKSPACE, DELETE, CURSORs, etc... keys too! TextField=CreateTextField(0,0,100,60,Mother,0) SetGadgetFilter TextField, ZahlenFilter Function ZahlenFilter%(event:TEvent,context:Object) Local Key%=event.data Select event.id Case EVENT_KEYDOWN Select Key Case 8,32,37,38,39,40,46,45 Return 1 Case 48,49,50,51,52,53,54,55,56,57 Return 1 Default Return 0 End Select Case EVENT_KEYCHAR Select Key Case 48,49,50,51,52,53,54,55,56,57 Return 1 Case 32,45 Return 1 Default Return 0 End Select End Select End Function if you want you can add a counting of digits, which would return 0 if they are is already to many. |