Multi-line StringGadget and 'going to the bottom'

Just starting out? Need help? Post your questions and find answers here.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Multi-line StringGadget and 'going to the bottom'

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post 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).
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post by TimmyTom »

Awesome, that works..

Thanks a lot!

Timmy
Post Reply