Page 1 of 1

Multi-line StringGadget and 'going to the bottom'

Posted: Mon Jul 26, 2004 3:44 am
by TimmyTom
Hi,

I have a multiline stringgadget and when the user does something usery (ie: stupid) it produces an error messagerequester..

Now, when the user leaves the messagerequester and i return the user to the stringgadget (after removing the error from the stringgadget, as they were dumb and made the error), i can get the cursor to move to the bottom of the stringgadget without problem..

However, the stringgadget resets it's scrolling to the top of the stringgadget..

How do i scroll the gadget down to the bottom again from code?

Timmy

Re: Multi-line StringGadget and 'going to the bottom'

Posted: Mon Jul 26, 2004 3:55 am
by PB
> the stringgadget resets it's scrolling to the top of the stringgadget

I can't get a StringGadget to do that after a MessageRequester... can you post
some code that demonstrates it? (When I tried it, the StringGadget didn't scroll
anywhere).

Posted: Mon Jul 26, 2004 4:02 am
by TimmyTom

Code: Select all

win = OpenWindow(1,10,10,200,200,#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered,"TEST")
If CreateGadgetList(WindowID())
  StringGadget(string_6,10,10,50,50,"",#PB_String_Multiline|#WS_VSCROLL)
EndIf

Repeat
  EventID.l = WaitWindowEvent()

  Select eventID
    Case #PB_Event_Gadget
      Select EventGadgetID()
        Case string_6
          newline = FindString(GetGadgetText(String_6),Chr(13) + Chr(10),1)
          If newline <> 0
            lcnt = CountString(GetGadgetText(String_6),Chr(13) + Chr(10))

            If lcnt + 1 > 5
              txt$ = GetGadgetText(String_6)
              txt$ = Left(txt$,Len(txt$) - 2)
              SetGadgetText(String_6,txt$)
              SendMessage_(GadgetID(String_6), #EM_SETSEL, Len(GetGadgetText(String_6)), Len(GetGadgetText(String_6)))
              MessageRequester("OOPS","The amount of lines exceeds" + Chr(10) + "the maximum length of " + Str(5) + " lines!")
            EndIf
          EndIf
      EndSelect
  EndSelect

  If EventID = #PB_Event_CloseWindow
    Quit = 1
  EndIf
Until Quit = 1
The above will throw the messagerequester when more than 5 lines are in the stringgadget.. and it'll reset the stringgadget to the top, instead of the bottom, where the cursor is.

Timmy

Posted: Mon Jul 26, 2004 4:32 am
by PB
Just stick this in before your current SendMessage line:

Code: Select all

SendMessage_(GadgetID(String_6), #EM_LINESCROLL, 0, 5)
BTW, it wasn't the MessageRequester causing the problem, it was SetGadgetText.

Posted: Mon Jul 26, 2004 4:52 am
by TimmyTom
Awesome, that works..

Thanks a lot!

Timmy