
Can't get richtextbox to scroll down to last line after update
Hi,
What version framework are you using? Have you applied the SP2? I can not
reproduce your problem in my side. I paste my code here for your reference.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents textbox1 As System.Windows.Forms.RichTextBox
<System.Diagnostics.De{*filter*}StepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.textbox1 = New System.Windows.Forms.RichTextBox()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(184, 232)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(88, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'textbox1
'
Me.textbox1.Location = New System.Drawing.Point(8, 16)
Me.textbox1.Name = "textbox1"
Me.textbox1.Size = New System.Drawing.Size(280, 192)
Me.textbox1.TabIndex = 1
Me.textbox1.Text = "RichTextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.textbox1, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
textbox1.Text &= "This is a update" + vbCrLf
'Dim i As Integer
'For i = 0 To 100
' textbox1.Text &= "This is a update" + vbCrLf
'Next
textbox1.SelectionStart = textbox1.Text.Length
textbox1.SelectionLength = 0
textbox1.Focus()
textbox1.ScrollToCaret()
End Sub
End Class
I hope this helps. If you have any questions, please reply to this post.
Best Regards,
Jun Su
Microsoft Support
---
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Subject: Can't get richtextbox to scroll down to last line after update
| Date: Sun, 9 Mar 2003 15:47:50 -0500
|
| Hi, I'm trying to get a richtextbox in my VB.net program to automatically
scroll
| down to the last line each time the text is appended in it. I cannot for
the
| life of me get it to work. I've done web and newsgroup searches and the
| consensus has been you can accomplish it by the following.
|
| txtbox.Text &= "This is an update" & vbCrLf
| txtbox.SelectionStart = txtbox.Text.Length()
| txtbox.SelectionLength = 0
| txtbox.Focus()
| txtbox.ScrollToCaret()
|
| It won't work. It still stays at the top of the text box. I've even tried
| putting txtbox.Focus() after txtbox.ScrollToCaret(), but no dice. Any
ideas as
| to why it won't work or how I can fix it?
|
| Bill
|
|
|