Microsoft KB Archive/820629

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

Article ID: 820629

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





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:   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(&quot;call TextBox2.Select&quot;) 'Select TextBox2 on TabPage2. TextBox2.Select 'Display the name of the current ActiveControl. Console.WriteLine(&quot;Form.ActiveControl after Select: &quot; + Me.ActiveControl.Name) Visual C# .NET Code //Select TabPage2. tabControl1.SelectedTab =tabPage2; Console.WriteLine(&quot;call textBox2.Select&quot;); //Select textBox2 on TabPage2. textBox2.Select; //Display the name of the current ActiveControl. Console.WriteLine(&quot;Form.ActiveControl after Select: &quot; + this.ActiveControl.Name);   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(&quot;set Form.ActiveControl = TextBox2&quot;) 'Set TextBox2 as the ActiveControl. Me.ActiveControl = TextBox2 'Display the name of the current ActiveControl. Console.WriteLine(&quot;Form.ActiveControl after set: &quot; + Me.ActiveControl.Name) Visual C# .NET Code //Select TabPage2. tabControl1.SelectedTab =tabPage2; Console.WriteLine(&quot;set Form.ActiveControl = textBox2&quot;); //Set textBox2 as the ActiveControl. this.ActiveControl = textBox2; //Display the name of the current ActiveControl. Console.WriteLine(&quot;Form.ActiveControl after set: &quot; + this.ActiveControl.Name);  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.



Steps to Reproduce the Problem
 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. From the Toolbox, drag a TabControl to Form1.</li> Right-click TabControl1, and then click Properties.</li> In the Properties window, click the TabPages property, and then click the ellipsis (...).</li> In TabPage Collection Editor, click Add two times.

By default, TabPage1 and TabPage2 are created.

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

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

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

<div class="references_section">