By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Anchoring problem

P: n/a
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!
Nov 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
c.Anchor = AnchorStyle.Top And AnchorStyle.Bottom

Try: c.Anchor = AnchorStyle.Top OR AnchorStyle.Bottom
--
Greetings,
Josip Medved
http://www.jmedved.com

Nov 17 '06 #2

P: n/a
Josip,

You be the man! That worked!

It was just the syntax all along, geez.

"Josip Medved" wrote:
c.Anchor = AnchorStyle.Top And AnchorStyle.Bottom

Try: c.Anchor = AnchorStyle.Top OR AnchorStyle.Bottom
--
Greetings,
Josip Medved
http://www.jmedved.com

Nov 17 '06 #3

P: n/a
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.

"Josip Medved" wrote:
c.Anchor = AnchorStyle.Top And AnchorStyle.Bottom

Try: c.Anchor = AnchorStyle.Top OR AnchorStyle.Bottom
--
Greetings,
Josip Medved
http://www.jmedved.com

Nov 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.