Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

Posted

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

Posted

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

Don't ask what your country can do for you, ask what you can do for your country...

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...