Microsoft KB Archive/822490

= BUG: The control size is not preserved when a form is minimized and then the form is restored =

Article ID: 822490

Article Last Modified on 11/26/2007

-

APPLIES TO


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

-





SYMPTOMS
You minimize a form that has a control, and then you change the size of the control while the form is minimized. When you restore the form, the control size values that you set while the form was minimized are not preserved.



CAUSE
This bug occurs when you set the Anchor property of the control to Top, Bottom, Left, Right and you set the size of the control at run time.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, start a new Microsoft Windows application by using Microsoft Visual Basic .NET, Microsoft Visual Basic 2005, Microsoft Visual C# .NET, or Microsoft Visual C# 2005.

By default, Form1 is created. Add a TextBox control to Form1. Right-click TextBox1, and then click Properties. In the Properties dialog box, set the Multiline property to True. Set the Size property to 200,200. Set the Anchor property to Top, Bottom, Left, Right.</li> Add a Button control to Form1.</li>  Add the following code to the Button1_Click event handler:

Visual Basic .NET or Visual Basic 2005 Code 'Minimize the form. Me.WindowState = FormWindowState.Minimized 'Set the size of the TextBox in the Minimized form. Me.TextBox1.Size = New Size(100, 100) Console.WriteLine(&quot;size of TextBox1 on the minimized form is:&quot; & TextBox1.Size.ToString) 'Display the form in the normal state. Me.WindowState = FormWindowState.Normal Console.WriteLine(&quot;size of TextBox1 after bringing to Normal state is:&quot; & TextBox1.Size.ToString) Visual C# .NET or Visual C# 2005 Code //Minimize the form. this.WindowState = FormWindowState.Minimized; //Set the size of the TextBox in the Minimized form. this.textBox1.Size = new Size(100, 100); Console.WriteLine(&quot;size of TextBox1 on the minimized form is:&quot; + textBox1.Size.ToString); //Display the form in the normal state. this.WindowState = FormWindowState.Normal; Console.WriteLine(&quot;size of TextBox1 after bringing to Normal state is:&quot; + textBox1.Size.ToString); </li> In Solution Explorer, right-click WindowsApplication1, and then click Properties.</li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.</li> Click Button1.

The size of the TextBox is not restored. Notice the output in the Output window.</li></ol>

<div class="references_section">