dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[DotGNU]Winforms anchoring and docking


From: Simon Guindon
Subject: [DotGNU]Winforms anchoring and docking
Date: Sun, 15 Jun 2003 20:48:21 -0400

Ok as requested I'm going to explain how anchoring and docking works in
winforms so rhys and everyone can understand since nobody is really
developing along side the real winforms, mostly going from documents I'm
sure.

Ok the first thing to understand is the difference between anchoring and
docking.  Docking makes a control attach to the side of its parent
control, anchoring just anchors a side of the control, to a side of its
parent.  This probably sounds the same but in different words, its kind
of hard to explain, but its not the same.  By default, controls anchor
top, and left sides.  Which means if the window is resized, its anchored
to the top and left, and it will not move.  If for example you anchor it
top, left and right, when you resize the window, say to make it wider,
the controls right edge will extent to follow the windows resizing.  Its
not attached to any side, your just "anchoring" the side of the control
to the side of the parent control.

Let me throw some screenshots at you to explain anchoring because
docking is pretty straight forward.
Here is an example of anchoring left and top, when the window is
resized, it will not resize along with it.

See anchor1.jpg and anchor2.jpg as attached in this email

Now I will change the buttons anchoring to top, left and right, so the
right side should resize along with the window resizing.

See anchor3.jpg

Does this explain anchoring well?  If I were to set anchoring to top,
left, right and bottom, both the right and bottom would extend with the
window.  If I were to anchor it to say the right only, when the window
is resized bigger, the button would follow that edge.

See anchor4.jpg

Now to explain docking a tad more, you have these options for docking a
control:
Top, Left, Right, Bottom, Fill (middle) and None.

If you dock 2 controls to the left, they will be side by side

See dock1.jpg

Now in VS.NET I can right click on say button2, and in the context menu
pick "bring to back" and it makes button2 the first to the left, then
button1, or you can do "bring to front".  This just changed the order
that the controls are added to the form so that the one you want is
first.

For example, if I set "send to back" on button2, so it's the first one,
the code generated by VS.NET is:

this.Controls.AddRange(new System.Windows.Forms.Control[]
{
        this.button1,
this.button2
});

If I want button1 right on the left side, then button two, the code
looks like:

this.Controls.AddRange(new System.Windows.Forms.Control[]
{
        this.button2,
this.button1,
});

That's about all I can think of right now.  If there are any questions
please ask away.



-----------------------------
Simon Guindon
Nureality Networks
www.nureality.ca

Attachment: anchor2.jpg
Description: JPEG image

Attachment: anchor1.jpg
Description: JPEG image

Attachment: anchor4.jpg
Description: JPEG image

Attachment: anchor3.jpg
Description: JPEG image

Attachment: dock1.jpg
Description: JPEG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]