FIX: Anchored Control on Inherited Form Changes Location When You Recompile (316560)



The information in this article applies to:

  • Microsoft .NET Framework SDK 1.0
  • Microsoft .NET Framework SDK 1.1

This article was previously published under Q316560

SYMPTOMS

After you run or recompile a project, anchored controls may be restored to their original position on the base form.

When you create a new Windows Form by inheriting from a base form that has private anchored controls, you may encounter unexpected run-time and design-time behavior. When you first resize the inherited form in the designer, the controls move correctly with the form; however, at run time or when you recompile, the controls are restored to their original position on the base form.

RESOLUTION

You can work around this problem by using one of the following methods:
  • Wait until after you run InitializeComponent to resize the form. Do not resize the form in the designer.
  • In the base form, change the access modifier of anchored controls (for example, button1) to be Protected in the base class, as follows:
    • In Microsoft Visual C#, change Private to Protected:
      Protected System.Windows.Forms.Button button1;
      						
    • In Microsoft Visual Basic .NET, change Friend to Protected:
      Protected WithEvents Button1 As System.Windows.Forms.Button
      						

MORE INFORMATION

Steps to Reproduce Behavior

  1. Use either C# or Visual Basic .NET to create a new Windows Form application.
  2. On Form1, add a button with the default name of button1.
  3. Set the Anchor property of button1 to be bottom, right.
  4. Compile the project.
  5. On the Project menu, click Add inherited form.
  6. On the Add New Item dialog box, note that Form2 appears as the name of Inherited Form, and then click Open.
  7. On the Inheritance Picker dialog box, select Form1 as the component to inherit from, and then click OK.
  8. Resize the inherited form to make it wider than the base form. Note that the button moves correctly with the inherited form, and then compile the project again.

    Instead of remaining anchored at its current position on the inherited form, the button appears in the location where it was originally located on the base form.
This bug was corrected in Microsoft .NET Framework SDK 1.1.

Modification Type:MajorLast Reviewed:4/8/2003
Keywords:kbfix kbForms kbCtrl kbpending kbprb KB316560