views:

381

answers:

4

I have a base form. I place Ok and Cancel buttons on the bottom right of the form and anchor them Bottom and Right.

The inherited form does not honor the anchor properties of the Ok and Cancel buttons. Here are the exact steps to repro.

1- Create a base form with a button located at bottom/right. Anchor it there at Bottom,Right. 3- Create a new form that inherits from the base form, created in step 1. 4- Increase (in the designer) the second form's height or width. 5- You'll see that the button does not exactly move, thus dishonoring its anchor properties.

Am I doing something wrong, or does VS2008 simply not honor the anchor properties of the controls on the base form?

Thanks.

+1  A: 

It works for me.

How are you creating the inherited form? I go

  1. Build
  2. Add New -> Windows Form
  3. Select Windows Forms
  4. Select Inherited Form
  5. Select the original form

The button moves as expected.

Ray
+2  A: 

Mmm followed your steps and worked perfectly...

Make sure that the inherited form isn't overriding some properties in the designer... Mine "Inherited Form" only has this:

private void InitializeComponent()
{
    this.SuspendLayout();
    // 
    // Form2
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.ClientSize = new System.Drawing.Size(296, 154);
    this.Name = "Form2";
    this.ResumeLayout(false);

}
Ironicnet
+1  A: 

Do observe that something very naughty is going on. The properties of a private field of the base class are changing (the Location property), completely violating .NET accessibility rulez. That works up to a point, but runs out of gas once you run your project. The fix is easy, change the Modifiers property of your button from Private to Protected.

Hans Passant
A: 

Gentlemen, I asked the wrong question. Please disregard. I've re-submitted the question in the correct form here: http://stackoverflow.com/questions/443777/does-visual-inheritance-work-with-user-controls-in-vs2008

AngryHacker