Anchoring problem

G

Guest

This works properly:

1. Create a new Form and set it's size to 229, 474.

2. Drag a Panel to the form and set the following properties:
Size = 216, 438
Location = 3,1
Anchor = Top, Bottom

3. Add a PictureBox control to the top of the panel and set the following
properties:
Size = 210, 56
Location = 3,2
Anchor = Top, Left
and then stick a image into the PictureBox

4. Add a LinkLabel control to the bottom of the panel and set the following
properties:
Text = "LinkLabel Test"
Size = 126,13
Location = 52, 413
Anchor = Bottom, Left

Run the program and try resizing the form. You'll notice as you make the
form wider, the panel stays centered inside the form and if you expand the
form vertically the link label will move up and down properly. So everything
is working as it should.

Now, I am creating a User Control which I just copied the above Panel to the
UserControl and adding it to the Form like this:

Dim c As New UserControl1
Me.Controls.Add(c)

and run the program. You'll notice the anchoring no longer works and as you
expand the form, the UserControl stays stationary in the top left corner of
the form.

How do I get the UserControl to behave just like the Panel being added to
the form?

This has been very frusturating for me over the past few days since I have
tried setting the anchor programatically when creating the control and adding
it to the form like this:

Dim c As New UserControl1
c.Anchor = AnchorStyle.Top And AnchorStyle.Bottom
Me.Controls.Add(c)

That just causes the UserControl to center itself on the Form and the Panel
inside the UserControl ignores the anchors set.

What am I doing wrong?

Please help!
 
J

Josip Medved

c.Anchor = AnchorStyle.Top And AnchorStyle.Bottom

Try: c.Anchor = AnchorStyle.Top OR AnchorStyle.Bottom
 
G

Guest

How do I get my UserControl to resize itself properly after I remove it from
the form and then add it again.

If I resize form and add the UserControl it appears in the upper left hand
corner and looses it's anchor capabilities.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top