473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Anchoring problem

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
3 5126
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
1
by: Brian Conway | last post by:
I have a webform that I have a datagrid on that I want a button at the bottom of the grid to maintain its position with the datagrid, if the grid grows large then button needs to move down with it,...
3
by: Mad Joe | last post by:
Hi! I have a window form that contains 4 elements (2x2) on one panel. Those 4 elements are GroupBoxes of the exact same size, sorted like this: groupBox1 groupBox2 groupBox3 groupBox4 ...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
0
by: daveryan78 | last post by:
Hi all, I've been getting a strange problem with anchoring on my forms. I have a form where I put on a tabControl. I set it's anchoring to Top, Bottom, Left, Right. I put a number of tabPages on...
3
by: Steve | last post by:
I have two group boxes containing labels and textboxes that are next too each other. I want the group boxes and labels and textboxes to remain portionally the same as the form is resized. I've...
3
by: marfi95 | last post by:
My application consists of basically a treeview on the left side, along with a panel control that takes up the right side. When nodes are clicked on the left, the data on the right side of the...
1
by: sklett | last post by:
I've read several articles/blogs/threads about anchoring/docking child controls in a FlowLayoutPanel. It sounds like it *should* work, but I can't get it to work for the life of me. Jon Skeet: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.