Click to See Complete Forum and Search --> : vb.net 2003 autoscrolling textbox. Please help
Martin_SBT
April 25th, 2006, 05:12 PM
i got a textbox and i am unable to have it to automatically scroll down each time i add text to it! here is my code:
lstlog.Text = lstlog.Text & ActualPC & ": " & Excep.Message & vbCrLf
'lstlog.Refresh()
lstlog.SelectionStart = Len(lstlog.Text)
lstlog.ScrollToCaret()
lstlog.Select()
the above code been find by doing some internet research but doesnt work!
Please help
thanks in advance
Martin
kebo
April 25th, 2006, 05:37 PM
In what subroutine is that code? If it is in the Form_Load or the new constructor it won't work. This code work fine
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'just load the textbox with dum-dum stuff
Dim s As String = "asdlgkjadslgkjadlkgjadsljglagjlkafjgoidsfgojsovjrtiriiiiiiiiiiiiiiiiiiiiiiiiiiiiiidddddddddddddddddddddddddddddddddddddddddddjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
For i As Integer = 1 To 10
Me.tB.Text &= s
Next
'scroll the textbox
With tB
.SelectionStart = Me.tB.Text.Length
.ScrollToCaret()
End With
End Sub
Notice the code is in a button click event handler
HTH
kevin
Martin_SBT
April 25th, 2006, 05:49 PM
its in a timer_tick event. Tried to modify my code to follow your suggestion but still doesnt scroll down automatically: here is my code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
lstlog.Text = lstlog.Text & "Resolving Host Names to IP Addresses, Please wait..." & vbCrLf
'
Dim pclist As String
Dim IPstr As String
Dim pcArray As String() = Nothing
Dim s As String
'
'
pclist = GetListViewColumnAsString(PCListView, 0)
pcArray = pclist.Split(",")
'
For Each ActualPC In pcArray
lstlog.Text = lstlog.Text & "Resolving IP Addresses For: " & ActualPC & "..." & vbCrLf
lstlog.Refresh()
'MsgBox(ActualPC & " " & GetIPAddress(ActualPC))
IPstr = GetIPAddress(ActualPC) 'get the ip address
If IPstr = "unknown" Then ' if unable to resolve IP
AddSubitemTo(ActualPC, "unknown")
PCListView.Refresh()
lstlog.Text = lstlog.Text & "unable to resolve IP address For: " & ActualPC & "..." & vbCrLf
lstlog.SelectionStart = Me.lstlog.Text.Length
lstlog.ScrollToCaret()
'MsgBox("cannot resolve ip for : " & ActualPC)
Else ' else add ip to PClistview
'
AddSubitemTo(ActualPC, IPstr)
PCListView.Refresh()
lstlog.Text = lstlog.Text & "Success..." & vbCrLf
lstlog.SelectionStart = Me.lstlog.Text.Length
lstlog.ScrollToCaret()
'MsgBox(ActualPC & " " & GetIPAddress(ActualPC))
End If
Next ActualPC
'
lstlog.Text = lstlog.Text & "Finished resolving IP addresses!" & vbCrLf
lstlog.Refresh()
End Sub
kebo
April 25th, 2006, 05:56 PM
all I can say is try putting a
lstlog.Focus()before the lstlog.ScrollToCaret() because from MSDN
Note This method has no effect if the control does not have focus or if the caret is already positioned in the visible region of the control.
kevin
Martin_SBT
April 25th, 2006, 06:43 PM
just tried that and still doesnt work. Not sure what is going on.
HanneSThEGreaT
April 26th, 2006, 02:42 AM
One thought that comes to mind would be to use the SendMessage API and sending it a Scroll (I think it's EM_LINESCROLL) to scroll your textbox.
Shuja Ali
April 26th, 2006, 02:48 AM
The easiest of all would be to use the SelectedText property of the textbox to add text to it. lstlog.SelectionStart = lstlog.Text.Length
lstlog.SelectedText = ActualPC & ": " & Excep.Message & vbCrLfIf you use this code, you don't have to write extra code for scrolling the text. And it will be more faster that the method you have posted.
Martin_SBT
April 26th, 2006, 09:09 AM
Shuja
Your suggestion works grrrrreat! :thumb: :thumb:
Thanks much everyone for helping me! I really appreciate it!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.