resizing , resolutions and positioning!!!

G

giddy

hi ,
i have a big app at hand and i worried about resolutions and resizing
right from the start , basically i have two problems :

i tried *naively* to handle different resolutions by hardcoding
different sizes and setting them accordingly in the Form() construct ,
now i should call it before PerformLayout() , so when i put it into
the InitComponent() , windows designer cant handle this. Yes i can
just comment out the code and then uncomment it when i build a release
and it works but is there a way around this???

Also , what about handling resolutions itself? i have a 17in monitor
at 1024*768 , so will an app here look the same on a 15in monitor with
800*600??? or what about people with 17in monitors with a 800*600
resolution!!?!?!?


And then resizing? could someone just give me a general idea of how
its all done? i know certain controls have to be resized and others
repositioned , but i cant still get how i repos. and resize according
the change in the apps size???? I want to limit the app to just about
640*320 or less.

thanks
Gideon
 
D

DaveP

I Have not done this in c# but in win32
i use to get the dimensions of the desktop
than u know current resolution
unless you have a specific reason for handling resolution yourself....
I design at 1024/768.......for now thats a good resolution
and i dont really care what the client has...800/600 just about gone.....but
you could make ur windows behave like the clietn settings by finding out
current
Settings on the client machine...than you only have to deal with Resize and
you control placements in the resize event...etc...
since im new to c# i dont know the calls yet to find out client side
information
hope this helps a bit....
dave
 
B

Bruce Wood

hi ,
i have a big app at hand and i worried about resolutions and resizing
right from the start , basically i have two problems :

i tried *naively* to handle different resolutions by hardcoding
different sizes and setting them accordingly in the Form() construct ,
now i should call it before PerformLayout() , so when i put it into
the InitComponent() , windows designer cant handle this. Yes i can
just comment out the code and then uncomment it when i build a release
and it works but is there a way around this???

Also , what about handling resolutions itself? i have a 17in monitor
at 1024*768 , so will an app here look the same on a 15in monitor with
800*600??? or what about people with 17in monitors with a 800*600
resolution!!?!?!?

And then resizing? could someone just give me a general idea of how
its all done? i know certain controls have to be resized and others
repositioned , but i cant still get how i repos. and resize according
the change in the apps size???? I want to limit the app to just about
640*320 or less.

Either you're trying to do something very sophisticated, or you're
taking a sledgehammer to a fly here. If it's the former, then I
apologize for the simplistic advice, but here goes....

I never worry about resolution, except to be sure that the minimum
size for my form can fit on everyone's screen. The important thing for
me is the behaviour of controls on resizing. You haven't mentioned
whether you're using .NET 1.1 or .NET 2.0. There are a few differences
between the two.

There are two control properties that regulate your control's
behaviour upon resizing: Anchor and Dock. Anchor indicates that the
control should maintain its position relative to a point in its
container control. The default is Top, Left, meaning that as the
container resizes, the control will maintain a constant distance from
the top left corner of its container. You can set Anchor to more than
two sides (or less than two, as I recently discovered) and the control
will change shape with its container. For example, if you anchor a
control to Top, Left, Right, then as its container gets wider or
narrower, the control will get wider or narrower to maintain constant
distance from those three sides.

Dock causes a control to "stick" to, and fill, one side of its
container. If you set a ListView Dock Left, for example, it will
"glom" onto the left side of its container and maintain a constant
width. As the container gets taller or shorter, the control will get
correspondingly taller or shorter. As the control gets wider or
narrower, the control will maintain its size.

Now, here's the trick: you can get a lot of mileage out of these two
properties if you nest your controls within panels. For example, I
have a lot of forms that have buttons along their bottom edge. So, I
add a Panel to the form, set it to Dock Bottom, then add the buttons
to the panel. I add a second Panel to the form and set it Dock Fill,
so it takes up the rest of the space on the form; the other controls
go into that Panel. If I want to divide the remaining space in two
(for example a ListView on the left and other controls on the right)
then I place panels within the upper (Dock Fill) panel and set them
Dock Left and Dock Fill to divide that space into two horizontally.

Using this technique you can carve your form into areas where you want
to place controls, and have each area resize the way you want it to
when the form resizes. No need to handle the Resize event or anything
so complicated as that.

Then, once you're done, you can set MinSize for your Form, to indicate
that the user shouldn't be able to make it any smaller than X, because
it doesn't look good any smaller than that.

That, for me, is usually it. No need to worry about resolutions, etc.
 
R

RobinS

Bruce Wood said:
Either you're trying to do something very sophisticated, or you're
taking a sledgehammer to a fly here. If it's the former, then I
apologize for the simplistic advice, but here goes....

I never worry about resolution, except to be sure that the minimum
size for my form can fit on everyone's screen. The important thing for
me is the behaviour of controls on resizing. You haven't mentioned
whether you're using .NET 1.1 or .NET 2.0. There are a few differences
between the two.

There are two control properties that regulate your control's
behaviour upon resizing: Anchor and Dock. Anchor indicates that the
control should maintain its position relative to a point in its
container control. The default is Top, Left, meaning that as the
container resizes, the control will maintain a constant distance from
the top left corner of its container. You can set Anchor to more than
two sides (or less than two, as I recently discovered) and the control
will change shape with its container. For example, if you anchor a
control to Top, Left, Right, then as its container gets wider or
narrower, the control will get wider or narrower to maintain constant
distance from those three sides.

Dock causes a control to "stick" to, and fill, one side of its
container. If you set a ListView Dock Left, for example, it will
"glom" onto the left side of its container and maintain a constant
width. As the container gets taller or shorter, the control will get
correspondingly taller or shorter. As the control gets wider or
narrower, the control will maintain its size.

Now, here's the trick: you can get a lot of mileage out of these two
properties if you nest your controls within panels. For example, I
have a lot of forms that have buttons along their bottom edge. So, I
add a Panel to the form, set it to Dock Bottom, then add the buttons
to the panel. I add a second Panel to the form and set it Dock Fill,
so it takes up the rest of the space on the form; the other controls
go into that Panel. If I want to divide the remaining space in two
(for example a ListView on the left and other controls on the right)
then I place panels within the upper (Dock Fill) panel and set them
Dock Left and Dock Fill to divide that space into two horizontally.

Using this technique you can carve your form into areas where you want
to place controls, and have each area resize the way you want it to
when the form resizes. No need to handle the Resize event or anything
so complicated as that.

Then, once you're done, you can set MinSize for your Form, to indicate
that the user shouldn't be able to make it any smaller than X, because
it doesn't look good any smaller than that.

That, for me, is usually it. No need to worry about resolutions, etc.

That was a great response. Very clear. I never really bothered to figure
out the difference between Anchor and Dock, and now I know. Thanks!

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
 
G

giddy

"> > Either you're trying to do something very sophisticated, or
you're

i think its the latter! , i knew there was some new crazy secret to
resizing in .NET , like DaveP i've done win32 too so i always this
idea one has to handle OnResize() . . .i remember seeing some source
just a few weeks ago that resized perfectly but had'nt even installed
a function for the resize event!!!! i thought of mentioning that ,
but did'nt for fear of people thinking ive *lost it*



Thanks so much , I agree with Robin , you reply was very clear ,
precise and very helpful.

I am using .NET 2.0! and C# 2.0! i'm sry i forgot to mention that!!

Gideon
 
B

Bruce Wood

I should point out one little quirk when it comes to docking: how
controls dock depends upon Z order. Specifically, if you choose
Dock.Fill for a control, it will fill all of the space left un-docked
by any controls _behind_ it. (Or, in programming terms, any controls
added to the container before it.)

If you use Dock.Fill and find your control (or panel) taking up too
much space (that is, filling space _behind_ some other controls that
you Docked to other sides of the container) then all you have to do is
select the Fill docked control and use "Bring to Front" to have it
fill correctly.

As well, in .NET 2.0 there is additional layout help: the splitter
control has been replaced by the much better SplitContainer, and there
are layout managers a la Java that allow you to do things like Flow
layout and Grid layout.
 

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