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

Article translations Article translations
Article ID: 822490 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.anchor(vs.71).aspx

Properties

Article ID: 822490 - Last Review: February 27, 2014 - Revision: 2.8
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
Keywords: 
kbnosurvey kbarchive kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbbug kbproperties kbwindowsforms kbforms kbctrl kbcontrol KB822490

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com