BUG: A control on the hidden TabPage is not visible when you use the Control.Select method or the Form.ActiveControl property in Visual Basic .NET or in Visual C# .NET (820629)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

SYMPTOMS

You may have a TabControl control on a Windows Form. You may add controls to the TabPages property of the TabControl. When you use the Form.ActiveControl property or the Control.Select method to set the focus for the control on the hidden TabPages, the focus is moved to the control. However, you cannot see the control.

RESOLUTION

To resolve the problem, select the hidden TabPages on the TabControl, and then follow these steps:
  1. Replace the existing code in the Button1_Click event handler with the following code:

    Visual Basic .NET Code
    'Select TabPage2. 
    TabControl1.SelectedTab = TabPage2
    Console.WriteLine("call TextBox2.Select()")
    'Select TextBox2 on TabPage2.
    TextBox2.Select()
    'Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after Select: " + Me.ActiveControl.Name)
    Visual C# .NET Code
    //Select TabPage2.
    tabControl1.SelectedTab =tabPage2;
    Console.WriteLine("call textBox2.Select()");
    //Select textBox2 on TabPage2.
    textBox2.Select();
    //Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after Select: " + this.ActiveControl.Name);
  2. Replace the existing code in the Button2_Click event handler with the following code:

    Visual Basic .NET Code
     'Select TabPage2. 
    TabControl1.SelectedTab = TabPage2
    Console.WriteLine("set Form.ActiveControl = TextBox2")
    'Set TextBox2 as the ActiveControl.
    Me.ActiveControl = TextBox2
    'Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after set: " + Me.ActiveControl.Name)
    Visual C# .NET Code
    //Select TabPage2.
    tabControl1.SelectedTab =tabPage2;
    Console.WriteLine("set Form.ActiveControl = textBox2");
    //Set textBox2 as the ActiveControl.
    this.ActiveControl = textBox2;
    //Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after set: " + this.ActiveControl.Name);
  3. On the Debug menu, click Start.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Problem

  1. In Microsoft Visual Studio .NET, create a new Microsoft Windows application. You can use either Visual Basic .NET or Visual C# .NET.

    By default, Form1 is created.
  2. From the Toolbox, drag a TabControl to Form1.
  3. Right-click TabControl1, and then click Properties.
  4. In the Properties window, click the TabPages property, and then click the ellipsis (...).
  5. In TabPage Collection Editor, click Add two times.

    By default, TabPage1 and TabPage2 are created.

    Click OK.
  6. From the Toolbox, drag a TextBox control to TabControl1.
  7. Click TabPage2, and then drag a TextBox control to TabControl1.
  8. Drag two Button controls to Form1.
  9. In the Properties window, set the Text property of Button1 to SelectControl, and then set the Text property of Button2 to SetActiveControl.
  10. Add the following code to the Click event of Button1.

    Visual Basic .NET Code
    Console.WriteLine("call TextBox2.Select()")
    'Select TextBox2 on TabPage2.
    TextBox2.Select()
    'Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after Select: " + Me.ActiveControl.Name) 
    Visual C# .NET Code
     Console.WriteLine("call textBox2.Select()");
    //Select textBox2 on TabPage2.
    textBox2.Select();
    //Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after Select: " + this.ActiveControl.Name);
  11. Add the following code to the Click event of Button2.

    Visual Basic .NET Code
    Console.WriteLine("set Form.ActiveControl = TextBox2")
    'Set TextBox2 as the ActiveControl.
    Me.ActiveControl = TextBox2
    'Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after set: " + Me.ActiveControl.Name)
    Visual C# .NET Code
    Console.WriteLine("set Form.ActiveControl = textBox2");
    //Set textBox2 as the ActiveControl.
    this.ActiveControl = textBox2;
    //Display the name of the current ActiveControl.
    Console.WriteLine("Form.ActiveControl after set: " + this.ActiveControl.Name);
  12. In Solution Explorer, right-click WindowsApplication1, and then click Properties.
  13. In the Output type list, select Console Application, and then click OK.
  14. On the Build menu, click Build Solution.
  15. On the Debug menu, click Start.
  16. Click SelectControl, and notice that you cannot see TextBox2. Notice the output that appears. You can see that TextBox2 is the ActiveControl.
  17. Click SetActiveControl. You cannot see TextBox2. Notice the output that appears. This is the behavior that is described in the "Symptoms" section.

REFERENCES

For more information about the TabControl control (Windows Forms), visit the following Microsoft Web site:

http://msdn.microsoft.com/library/en-us/vbcon/html/vboriTabStripCtlTasks.asp

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbWindowsForms kbTabCtrl kbCtrl kbControl kbbug KB820629 kbAudDeveloper