Share via

TabControl Issue

Saravanan Ganesn 11 Reputation points
2021-05-19T07:47:21.673+00:00

Hi Team

I have tab control in windows form. The tab control has two tabs . One tab contain form with textbox and another tab contain only textbox . What I am trying select the text from 1st tab but not able to select the text from the text box. I have no problem selecting the text from the second tab. We have attached the sample from following location.

Sample: https://1drv.ms/u/s!AsISs7GoFbYYgsFck1q05FFRR0U4bw?e=vQ5C9H

Kindly check the sample and let me know any way to solve this behavior?

Developer technologies | Windows Forms
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,661 Reputation points
    2021-05-19T09:04:21.85+00:00

    Hi SaravananGanesn-3331,
    First, you can give your textbox control a name for easy searching later.

    textBox.Name = "t1"  
    

    And the you need to cast the control in the TabPage back to Form before you can access the property.
    Please refer to the following code example:

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)  
        If tabControl1.SelectedTab IsNot Nothing Then  
      
            If tabControl1.SelectedTab.Controls.Count > 0 Then  
      
                If TypeOf tabControl1.SelectedTab.Controls(0) Is Form Then  
                    Dim f2 As Form = CType(tabControl1.SelectedTab.Controls(0), Form)  
                    label1.Text = f2.Controls.Find("t1", True).FirstOrDefault().Text  
                End If  
            End If  
        End If  
    End Sub  
    

    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.