VBOfficer Posted February 28, 2009 Posted February 28, 2009 Hi, I have a TabControl on my form with 1 TextBox in EACH Tab, total 2 TextBox... I fill each TextBox during a loop like this: For i As Integer = 1 To 100 ReportTextBoxX1.Text = ReportTextBoxX1.Text + i.ToString + vbNewLine ReportTextBoxX2.Text = ReportTextBoxX2.Text + i.ToString + vbNewLine Next However, I need to scroll down both TextBox in each Tab and have to use this code: Private Sub ReportTextBoxX1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportTextBoxX1.TextChanged ReportTextBoxX1.SelectionLength = 0 ReportTextBoxX1.SelectionStart = ReportTextBoxX1.Text.Length ReportTextBoxX1.ScrollToCaret() End Sub Private Sub ReportTextBoxX2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportTextBoxX2.TextChanged ReportTextBoxX2.SelectionLength = 0 ReportTextBoxX2.SelectionStart = ReportTextBoxX2.Text.Length ReportTextBoxX2.ScrollToCaret() End Sub However, the problem is that it only works for the SELECTED TAB, no matter which tab is selected. I do believe, this is because Windows Forms only shows one control at a time, and just update that... I was hoping this code solved my problem but it didn't: ...Before adding items to TextBox If Not ReportTextBoxX1.IsHandleCreated Then Dim handle As IntPtr = ReportTextBoxX1.Handle End If If Not ReportTextBoxX2.IsHandleCreated Then Dim handle As IntPtr = ReportTextBoxX2.Handle End If Can anyone help me please?! :confused: Quote
stumper66 Posted March 1, 2009 Posted March 1, 2009 How about handling the SelectedIndexChanged event on the tabcontrol to scroll the textbox to the charat? Private Sub TabControl1_SelectedIndexChanged(ByVal Sender As Object, ByVal e As EventArgs) Handles TabControl1.SelectedIndexChanged Dim sel As Integer = TabControl1.SelectedIndex Dim txt As Textbox = CType(TabControl1.Controls("TextBox" & (sel + 1).ToString()), TextBox) txt.ScrollToChar() End Sub Quote
OMID SOFT Posted March 6, 2009 Posted March 6, 2009 The problem is that controls on second tab were never displayed on screen so Windows Forms framework hasn't created Windows Handles for them. You can ensure that is done if you for example execute this code before you start your thread: If Not ReportTextBoxX2.IsHandleCreated Then Dim handle As IntPtr = ReportTextBoxX2.Handle End If Quote Don't ask what your country can do for you, ask what you can do for your country...
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.