Re: Fastest way to append text to a TextBox
- From: "Steve Gerrard" <mynamehere@xxxxxxxxxxx>
- Date: Wed, 2 Apr 2008 20:22:06 -0700
Phill W. wrote:
So, how can I get these lines into my TextBox /faster/?
Or, rather, why is updating the control /so/ slow, compared to hacking
strings around in memory?
' How about 10,000 lines, 5 seconds:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim n As Integer
Dim s As String = "Hello, World, how is it going these days, " _
+ "is this quick enough for you?" + vbCrLf
Dim sb As New System.Text.StringBuilder
Dim t As Date = Now
With Me.TextBox1
For n = 1 To 10000
sb.Append(n.ToString("0000") + " ")
sb.Append(s)
If n Mod 500 = 0 Then
.Text = sb.ToString
.SelectionStart = .Text.Length
.SelectedText = " "
Me.Text = n.ToString
My.Application.DoEvents()
End If
Next n
.Text = sb.ToString
.SelectionStart = .Text.Length
.SelectedText = " "
Me.Text = "Done: " + (Now - t).TotalSeconds.ToString("#,0.00")
End With
End Sub
.
- Follow-Ups:
- Re: Fastest way to append text to a TextBox
- From: Phill W.
- Re: Fastest way to append text to a TextBox
- References:
- Fastest way to append text to a TextBox
- From: Phill W.
- Fastest way to append text to a TextBox
- Prev by Date: Re: VB sql statement
- Next by Date: Re: adding an application shortcut to a form, and using icon of app as button
- Previous by thread: Re: Fastest way to append text to a TextBox
- Next by thread: Re: Fastest way to append text to a TextBox
- Index(es):