Stringgadget question

Just starting out? Need help? Post your questions and find answers here.
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Stringgadget question

Post by aszid »

is there a simple way to make a stringgadget stay scrolled down at the bottom?

i'm working on a chat client, and i'm using a read-only string-gadget for the conversation text, but the only way i know to add to it is by re-writing all of the text to the gadget. The problem being that when i do that, the window is scrolled to the top, leaving the latest text at the bottom, which needs to be scrolled to.

any suggestions would be appreciated.

thanks in advance,
Aszid
--Aszid--

Making crazy people sane, starting tomorrow.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

If it should read-only: how about using ListViewGadget() and SetGadgetState() for setting the last item as active one? (I know, only a quick and dirty solution... :twisted: )
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

use a listview gadget and use this:

Code: Select all

SetGadgetState(#LISTVIEW_GADGET, CountGadgetItems(#LISTVIEW_GADGET)-1)
--Kale

Image
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

hmm... i considered doing that, but i want to keep copy-paste functionality for the window, and i'm relatively sure you can't select just a portion of a line with a listviewgadget.

i was hoping for a quick flag or something that i could add at gadget creation that would make it stay at the bottom... but alas... maybe i'll go suggest that in the feature request thread.
--Aszid--

Making crazy people sane, starting tomorrow.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

try this: :D

Code: Select all

#Window_0 = 0

#Gadget_0 = 0
#Gadget_1 = 1
#Gadget_2 = 2


Procedure AddText()
    exsistingText.s = GetGadgetText(#Gadget_0)
    If exsistingText = ""
        SetGadgetText(#Gadget_0, GetGadgetText(#Gadget_1))
    Else
        SetGadgetText(#Gadget_0, exsistingText + Chr(13) + Chr(10) + GetGadgetText(#Gadget_1))
    EndIf
    lines = SendMessage_(GadgetID(#Gadget_0),#EM_GETLINECOUNT,0,0)
    SendMessage_(GadgetID(#Gadget_0), #EM_LINESCROLL, 0, lines)
EndProcedure

  If OpenWindow(#Window_0, 338, 281, 439, 254,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "New window ( 0 )")
    If CreateGadgetList(WindowID())
      StringGadget(#Gadget_0, 5, 5, 430, 210, "", #ES_MULTILINE | #ES_AUTOVSCROLL | #ES_AUTOHSCROLL | #WS_VSCROLL | #WS_HSCROLL)
      StringGadget(#Gadget_1, 5, 225, 345, 21, "")
      ButtonGadget(#Gadget_2, 358, 222, 77, 25, "Enter >>>")
      
    EndIf
  EndIf

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_EventGadget
        Select EventGadgetID()
            Case #Gadget_2
                AddText()
        EndSelect
  EndSelect

Until Event = #PB_EventCloseWindow
End
Last edited by Kale on Tue May 13, 2003 11:13 pm, edited 1 time in total.
--Kale

Image
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

awesome!

thanks alot for the help, i only needed 2 lines of the code, but those 2 work perfectly.

i REALLY love the community that purebasic has, i asked a question, and within a few hours 3 people made suggestions for me.

Professional technical support is nowhere near the quality that the community provides here.
--Aszid--

Making crazy people sane, starting tomorrow.
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

i found a better way to do this, so i thought i'd share with the forums.

this works on editorgadgets... haven't tried it on anything else.

all you need to do... is replace these 2 lines:

Code: Select all

    lines = SendMessage_(GadgetID(#Gadget_0),#EM_GETLINECOUNT,0,0) 
    SendMessage_(GadgetID(#Gadget_0), #EM_LINESCROLL, 0, lines) 
with this one line:

Code: Select all

SendMessage_(GadgetID(#Gadget_0), #EM_SCROLLCARET, 0,0)
--Aszid--

Making crazy people sane, starting tomorrow.
Post Reply