[Implemented] StringGadget maximal length

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PureBaser
User
User
Posts: 33
Joined: Mon Apr 10, 2006 8:47 pm
Location: Berlin, Germany
Contact:

[Implemented] StringGadget maximal length

Post by PureBaser »

A constant such in the way:

#PB_String_MaxLength

Thanks for reading
PB 4 | WinXP_SP2
Sub-Routine
User
User
Posts: 82
Joined: Tue May 03, 2005 2:51 am
Location: Wheeling, Illinois, USA
Contact:

Post by Sub-Routine »

Yes, a Flag to use with StringGadget...
We now return to our regularly scheduled programming...
maw

Post by maw »

Actually it's easy enough to do by yourself. This snippet is for PB4, Windows only, and handles backspace, delete, paste and such things.

Code: Select all

Procedure stringlength(gadget.l, length.l)
	text$ = GetGadgetText(gadget)
	textlength.l = Len(text$)

	If textlength > length
		SendMessage_(GadgetID(gadget), #EM_GETSEL, @startpos.l, @endpos.l)
		SetGadgetText(gadget, Left(text$, startpos - 1) + Mid(text$, startpos + 1, Len(text$) - 1))
		SendMessage_(GadgetID(gadget), #EM_SETSEL, startpos - 1, startpos - 1)
		FlashWindow_(WindowID(0), 1)
		MessageBeep_(-1)
	EndIf
EndProcedure


OpenWindow(0, 0, 0, 320, 240, "Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 20, 20, 200, 20, "")
StringGadget(1, 20, 50, 200, 20, "")
StringGadget(2, 20, 80, 200, 20, "")
StringGadget(3, 20, 110, 200, 20, "")

Repeat
	Select WindowEvent()
		Case #PB_Event_CloseWindow
			Break
		Case #PB_Event_Gadget
			gadget.l = EventGadget()
			Select gadget
				Case 0,1
					stringlength(gadget, 20)
				Case 2
					stringlength(gadget, 10)
				Case 3
					stringlength(gadget, 32)
			EndSelect
	EndSelect
ForEver
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

We could add an attribute for that, you're right. For Windows you can also use that:

Code: Select all


OpenWindow(0, 0, 0, 320, 240, "Test")
CreateGadgetList(WindowID(0))
StringGadget(0, 20, 20, 200, 20, "")
StringGadget(1, 20, 50, 200, 20, "")
StringGadget(2, 20, 80, 200, 20, "")
StringGadget(3, 20, 110, 200, 20, "")

SendMessage_(GadgetID(0), #EM_LIMITTEXT, 3, 0)

Repeat
   Select WindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_Gadget
         gadget.l = EventGadget()
   EndSelect
ForEver 
Post Reply