I would not use a MultiLineLabel as the container for the chat. I would use
a listbox, with each of the chat items being its own child of the listbox.
Sort by TagString or TagID, and set the sorted Tag to a timestamp.
Like so:
Public Class ChatMessageArea
Inherits StdListBox
Public Overrides Sub Initialize()
MyBase.Initialize()
SortAscending = True
Me.SortingMethod = SortingMethods.ByTagID
AllowFocus = True
End Sub
Public Sub AddMessage(ByVal M As String)
Dim lbl As New ChatRoomMessage
lbl.Initialize(M)
lbl.TagID = Now.Ticks
lbl.Width = Width
AddChild(lbl)
VScrollBar.Slider.Top = VScrollBar.BottomButton.Top -
VScrollBar.Slider.Height
End Sub
Private Sub IWasResized() Handles MyBase.Resized
For Each C As ChatRoomMessage In Children
C.Width = Width
Next
VScrollBar.Slider.Top = VScrollBar.BottomButton.Top -
VScrollBar.Slider.Height
End Sub
End Class
Public Class ChatRoomMessage
Inherits guiMultilineLabel
Public Overridable Sub Initialize(ByVal Msg As String)
Text = Msg
Hide()
Me.ForeShadowOffset = 0
With Me
With .Foreground.Base.Color
.Enabled = True
.RGBAInt = CONST_TV_COLORKEY.TV_COLORKEY_WHITE
End With
With .Border.Base.Color
.Disable()
.TVColor = New TV_COLOR(0.75, 0.75, 0.75, 0.9)
End With
End With
End Sub
End Class
As you can see, when I add a message, I create a new ChatRoomMessage object,
set the TagID to Now.Ticks, and the whole listbox is sorted by TagID.
When a message is added, the VScrollBar.Slider.Top is set to the top of the
bottom button minus the slider's height (basically "scrolled all the way
down").
Easy! :)
AddChild(MLText)
InitVScrollbar()
End Sub
End Class
Thanks!
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.169 / Virus Database: 270.6.21/1671 - Release Date: 9/14/2008
7:16 AM