Results 1 to 6 of 6

Thread: Scroll down in a textbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    26

    Scroll down in a textbox

    I have a textbox which is inside the second tab of a tab container.
    When I load the form, I load a file into that textbox. Is there any way to send the scrollbar at the bottom of the text box. I want to show only end part of the file.
    I have tried this, but it does not work (maybe because is inside a tab container?):
    Code:
    Textbox1.SelectionStart = Textbox1.TextLength 
    Textbox1.ScrollToCaret()
    thanks

  2. #2
    Lively Member
    Join Date
    Aug 2007
    Posts
    66

    Re: Scroll down in a textbox

    Use SelectionLength instead of start

    Code:
    TextBox1.SelectionLength = TextBox1.Text.Length
    TextBox1.ScrollToCaret()

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    26

    Re: Scroll down in a textbox

    Quote Originally Posted by Rykler View Post
    Use SelectionLength instead of start

    Code:
    TextBox1.SelectionLength = TextBox1.Text.Length
    TextBox1.ScrollToCaret()
    I have tested it and it did not work. What I see is than as it is place on a secondary tab, it did not receive focus. If I place the textbox outside tab container I see selection made, but it does not scroll to end.

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Scroll down in a textbox

    When you say the text box is on the second tab of a tab container - presumably this tab is the active tab? Or are you saying you load the form and populate the text box and then set the selection all while the tab containing the textbox is inactive, and when you switch to the 2nd tab the selection is reset?

    I just want to be sure I understand the sequence of events you are going through.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    26

    Re: Scroll down in a textbox

    Quote Originally Posted by keystone_paul View Post
    When you say the text box is on the second tab of a tab container - presumably this tab is the active tab? Or are you saying you load the form and populate the text box and then set the selection all while the tab containing the textbox is inactive, and when you switch to the 2nd tab the selection is reset?

    I just want to be sure I understand the sequence of events you are going through.
    No, the tab which has the textbox is the second one and is not active/visible. The active tab is the first one.
    When I load the form, I load the text in the textbox, but as it is not visible I can not get it to scroll down to the end. I want that when clicking second tab, the textbox automaticaly scroll to the end

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Scroll down in a textbox

    The problem seems to be finding the right event to trap. If I set up a similar form and put this code :

    Code:
       Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    
            If CType(sender, TabControl).SelectedIndex = 1 Then
                TextBox1.Select(TextBox1.TextLength, 1)
                TextBox1.ScrollToCaret()
                TextBox1.Focus()
            End If
    
        End Sub
    That seems to work (assuming of course that the textbox isn't empty!)
    Last edited by keystone_paul; May 12th, 2009 at 05:51 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width