Page 1 of 1

string gadget and focus setting

Posted: Thu Feb 24, 2005 3:17 pm
by chippy73
I am putting say, 5 lines of text under program control to a string gadget.

Fine it displays the 5 lines of text.

I set ActivateGadget but the cursor is at the beginning of the text on the first line.

How do I get it to appear say at the end of the text so that I can enter text manually from the keyboard?

My lines of code:-

Code: Select all

SetGadgetText(#Gadget_Form1_Editortx,textin1$)
         ActivateGadget(#Gadget_Form1_Editortx)
I think maybe SendMessage might be a clue but not sure.

Any help welcomed.

Alan

Posted: Thu Feb 24, 2005 5:04 pm
by Sparkie
Try this one...

Code: Select all

#Window_Main = 0 
#Gadget_Form1_Editortx = 0 
Procedure ActivateToEnd(gadID)
  ActivateGadget(gadID)
  stringLen = Len(GetGadgetText(gadID))
  SendMessage_(GadgetID(gadID), #EM_SETSEL, stringLen, stringLen)
EndProcedure

If OpenWindow(#Window_Main, 0 ,0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget") And CreateGadgetList(WindowID(0)) 
  StringGadget(#Gadget_Form1_Editortx, 10, 10, 280, 180, "", #PB_String_MultiLine) 
  For l = 0 To 4
    t$ + "Line " + Str(l) + Chr(13) + Chr(10)
    SetGadgetText(#Gadget_Form1_Editortx, t$)
  Next l
  AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Control | #PB_Shortcut_R, 1) 
  ; --> call procedure to set caret to end of StringGadget
  ActivateToEnd(#Gadget_Form1_Editortx)
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_EventMenu And EventMenuID() = 1 
      txstring$ = GetGadgetText(#Gadget_Form1_Editortx) 
      SetGadgetText(#Gadget_Form1_Editortx, txstring$ + Chr(18)) 
    EndIf 
  Until event = #PB_Event_CloseWindow 
EndIf 
End

Posted: Fri Feb 25, 2005 9:08 am
by chippy73
Sparkie,

Many thanks for the solution. It works fine. It's knowing that #EM_SETSEL existed ! I knew there had to be a command somewhere to do it.

Thanks again.

Alan