aviad wrote:
I am writing a Form application
I need it to fit both resolution of 1600*1200 and 800*600
(and any other resolution that might jump in)
the application is meant for regular PCs
another question is what the difference between the Dock and Anchor
properties?
Anchor maintains a constant distance between the anchored side(s) of
the control and the corresponding side(s) of the container. So, if you
place a TextBox directly on a Form, and Anchor the TextBox
Left,Top,Right, then as you resize the Form the TextBox will stay a
constant distance from the top of the form, but get wider or narrower
depending upon the size of the form.
Dock does one of five different things, depending upon its setting.
Dock Left means that the control will always be pressed against the
left edge of the container. As the container gets bigger or smaller,
the control will maintain a constant width but will always get taller
or shorter to fill the entire height of the container.
For example, if you have a ListView and set it to Dock Left, it will
always have the same width, and will always be against the left edge of
the Form, but will get taller or shorter to always fill the Form
vertically.
Dock Right means the same thing but the control will always be pressed
against the right edge of the container.
Dock Top means that the control will always be pressed against the top
of the container. The control will maintain a constant height, but will
grow or shrink its width to always take up the full width of the
container.
Dock Bottom means the same thinge but the control will always be
pressed against the bottom edge of the container.
Dock Fill means that the control will fill the entire container.
If there are several docked controls in one container, they are docked
back to front (in "Z order"): the first control docks to the edge of
the container, the second (in back-to-front order) docks into the space
left in the container after the first control docks, etc.
Now, here's the trick to it: use Panels. The secret (in VS2003, at
least) to making nicely resizing applications is to put your controls
within Panels and then dock the panels.
For example, I have a classic "maintenance screen" form: buttons along
the bottom (including OK and Cancel), ListView on the left with all of
the items that can be maintained, and textboxes and comboboxes on the
right that when you click on an item in the list view, it populates the
controls on the right with properties that the user can change.
What I want is that the buttons always stay along the bottom. As the
form is made taller, the ListView gets taller, but blank space opens up
on the right bottom, because the textboxes, etc, don't grow. As the
form is made wider, the additional width is given to the ListView,
because the controls on the right don't benefit from additional width.
This is how to set it up (in VS2003, .NET 1.1):
Add a Panel to the form, call it buttonPanel. Dock it Bottom and make
it high enough to hold the buttons. Put the buttons in here. The
buttons can have the default Dock and Anchor settings.
Add another panel to the form, call it detailsPanel. Dock it Right and
make it wide enough to hold the text boxes / combo boxes for the item
details. Put the text boxes and combo boxes in here.
Add the ListView to the form. Dock it Fill. It should fill the space up
to the edges of the buttonPanel and the detailsPanel.
Now, as you resize the form, you should see the ListView growing and
shrinking to take up the space.
Now, in VS2005 (.NET 2.0) there is something called LayoutManagers that
allow you to do nicer stuff / use fewer panels-within-panels, but the
same tricks still work in .NET 2.0: decide how you want your Form to
act when it's resized, block it out using docked Panels, then place
controls on the panels.
Oh, and it's nice to your user to use a Splitter (in VS2003) / a
SplitContainer (in VS2005) to allow your user to resize the areas you
allocate to various controls. Get the docking / anchoring working
first, though, so that you understand it... then play with splitters.
You can also try reading this, which I just found:
http://msdn.microsoft.com/library/de...NETVBdev05.asp