Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

It seems to be strange, but in a loop, when I add some text to the text box like this:

 

For X = 1 to 100

TextBox1.Text = TextBox1.Text + "Text" + vbNewLine

Next

 

However, the scroll bar will stay at top and I can only see the first few lines of text box, even if I move the scroll bar to down, it will jump back to top as soon as text inside the text box changes.

I want to change this scenario, so scroll bar will stay at down so I can see the last lines of text inside text box.

I don't know how can this be done, but I know it's possible because I've seen some applications like this! :confused:

Thank you.

Posted

SelectionStart

 

A quick-and-dirty implementation might looks like this:

 

For X = 1 to 100
   TextBox1.Text += "Text" + ControlChars.NewLine
   TextBox1.SelectionStart = TextBox1.Text.Length
Next

 

Good luck! :cool:

Never trouble another for what you can do for yourself.
  • 4 weeks later...
Posted

Paul's code didn't work for me. But this does:

 

   Private Const WM_VSCROLL As Int32 = &H115
   Private Const SB_BOTTOM As Int32 = 7

   Private Declare Auto Function SendMessage Lib "user32.dll" ( _
       ByVal hwnd As IntPtr, _
       ByVal wMsg As Int32, _
       ByVal wParam As Int32, _
       ByVal lParam As Int32 _
   ) As Int32

   Private Sub AddLine(ByVal loDestination As RichTextBox, ByVal lsText As String)
       With loDestination
           .AppendText(lsText & ControlChars.NewLine)
           SendMessage(loDestination.Handle, WM_VSCROLL, SB_BOTTOM, 0)
       End With
   End Sub

   Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
       Dim i As Integer = 0

       For i = 0 To 300
           AddLine(txtProgress, "Line " & i)
       Next
   End Sub

 

Pete

  • Leaders
Posted

Try this.


For X = 1 to 100
TextBox1.Text += "Text" + ControlChars.NewLine
TextBox1.SelectionStart = TextBox1.Text.Length
[i] TextBox1.ScrollToCaret()[/i]
Next
[/Code]

[sIGPIC]e[/sIGPIC]
Posted
Try this.


For X = 1 to 100
TextBox1.Text += "Text" + ControlChars.NewLine
TextBox1.SelectionStart = TextBox1.Text.Length
[i] TextBox1.ScrollToCaret()[/i]
Next
[/Code]

 

Nope, doesn't work. The only one I could get to work was the code I posted. Your code does make sense. But it doesn't work in VS 2005 for me. :(

 

 

Pete

Posted

Works fine here:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim i As Integer
       For i = 1 To 100
           TextBox1.Text += "Text" + i.ToString + ControlChars.NewLine
           TextBox1.SelectionStart = TextBox1.Text.Length
           TextBox1.ScrollToCaret()
       Next
End Sub

Posted
Works fine here:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim i As Integer
       For i = 1 To 100
           TextBox1.Text += "Text" + i.ToString + ControlChars.NewLine
           TextBox1.SelectionStart = TextBox1.Text.Length
           TextBox1.ScrollToCaret()
       Next
End Sub

 

Hmm... I wonder why it doesn't work for me. I have a regular textbox, with "Multiline=True", and "Scrollbar=Vertical". Is that what you have? Am I missing something? I am trying it in VS 2005. Is that what you are using?

 

Thanks,

Pete

Posted
Hmm... I wonder why it doesn't work for me. I have a regular textbox, with "Multiline=True", and "Scrollbar=Vertical". Is that what you have? Am I missing something? I am trying it in VS 2005. Is that what you are using?

 

Thanks,

Pete

 

Yes. :confused:

When I run this code I see the numbers climb up to 100 and the scrollbar stays at the bottom.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...