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



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# 2005, Express Edition
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

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 "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. 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.
  2. Add a TextBox control to Form1.
  3. Right-click TextBox1, and then click Properties.
  4. In the Properties dialog box, set the Multiline property to True.
  5. Set the Size property to 200,200.
  6. Set the Anchor property to Top, Bottom, Left, Right.
  7. Add a Button control to Form1.
  8. 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("size of TextBox1 on the minimized form is:" & TextBox1.Size.ToString)
    'Display the form in the normal state.
    Me.WindowState = FormWindowState.Normal
    Console.WriteLine("size of TextBox1 after bringing to Normal state is:" & 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("size of TextBox1 on the minimized form is:" + textBox1.Size.ToString());
    //Display the form in the normal state.
    this.WindowState = FormWindowState.Normal;
    Console.WriteLine("size of TextBox1 after bringing to Normal state is:" + textBox1.Size.ToString());
  9. In Solution Explorer, right-click WindowsApplication1, and then click Properties.
  10. On the Build menu, click Build Solution.
  11. On the Debug menu, click Start.
  12. Click Button1.

    The size of the TextBox is not restored. Notice the output in the Output window.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbBug kbProperties kbWindowsForms kbForms kbCtrl kbControl KB822490 kbAudDeveloper