Page 1 of 1
Default Cursor Position In StringGadget
Posted: Mon Apr 02, 2007 9:08 pm
by Karbon
Is it an accepted default for the cursor to be on the right side of the text if a textbox receives focus with the keyboard (through 'tabbing')?
Either that or highlighting the text seems to me to be the best default.
I know I can
SendMessage_(GadgetID(TheGadgetID), #EM_SETSEL, stringLen, stringLen)
...but when you're faced with adding that for every single stringgadget it becomes a lot of work.
Doesn't the right-cursor or auto-highlight make sense as the default?
Posted: Mon Apr 02, 2007 9:39 pm
by netmaestro
With this snippet you can write once and it will handle every string gadget in your app:
Code: Select all
Select EventType()
;
; Other event stuff...
;
Case #PB_EventType_Focus
cls$ = Space(50)
GetClassName_(GadgetID(EventGadget()), @cls$, 50)
If UCase(cls$) = "EDIT"
length = Len(GetGadgetText(EventGadget()))
SendMessage_(GadgetID(EventGadget()), #EM_SETSEL, length, length)
EndIf
;
; More event stuff...
;
I'm not 100% certain but I believe the StringGadget is the only PB gadget that handles the #PB_EventType_Focus, which would simplify things a bit.
Posted: Mon Apr 02, 2007 9:46 pm
by freak
netmaestro: in PB4, you can use GadgetType() to better determine the type.
Posted: Mon Apr 02, 2007 9:54 pm
by Karbon
Nice!
Thanks guys!
Posted: Mon Apr 02, 2007 10:00 pm
by netmaestro
Ah, thx freak, I gotta stop thinking in api :roll:
Posted: Fri Apr 06, 2007 12:12 am
by byo
Thank you. This has helped me a lot. I use this code and it works. Also if you put 0 as the starting text and -1 at the end, it will select all text.
Code: Select all
objeto = EventGadget()
Select EventType()
Case #PB_EventType_Focus
If GadgetType(objeto) = #PB_GadgetType_String
SendMessage_(GadgetID(objeto), #EM_SETSEL, 0, -1)
EndIf
EndSelect
Posted: Fri Apr 06, 2007 12:49 am
by Karbon
Great stuff - thanks again!
Re: Default Cursor Position In StringGadget
Posted: Fri Apr 06, 2007 1:14 am
by PB
> Is it an accepted default for the cursor to be on the right side of the text if
> a textbox receives focus with the keyboard (through 'tabbing')?
Depends on the locale. Arabic would have the cursor at the left.
