SIMIN Posted May 9, 2008 Posted May 9, 2008 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. Quote
MrPaul Posted May 9, 2008 Posted May 9, 2008 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: Quote Never trouble another for what you can do for yourself.
digioz Posted May 31, 2008 Posted May 31, 2008 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 Quote
Leaders snarfblam Posted June 1, 2008 Leaders Posted June 1, 2008 Try this. For X = 1 to 100 TextBox1.Text += "Text" + ControlChars.NewLine TextBox1.SelectionStart = TextBox1.Text.Length [i] TextBox1.ScrollToCaret()[/i] Next [/Code] Quote [sIGPIC]e[/sIGPIC]
digioz Posted June 1, 2008 Posted June 1, 2008 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 Quote
Erel Posted June 1, 2008 Posted June 1, 2008 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 Quote
digioz Posted June 1, 2008 Posted June 1, 2008 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 Quote
Erel Posted June 2, 2008 Posted June 2, 2008 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.