Automatic resize of controls on form

  • Thread starter Finn Stampe Mikkelsen
  • Start date
F

Finn Stampe Mikkelsen

I'm about to do a new application and so far i have only made none-resizable
forms.. I want to try to do an app, that can be resized by the user.

I was thinking along the lines of doing a initial size config, based on the
screen resolution and then letting the user drag the screen og via the menu
select preset resolutions of the app (limited by the gfx capablillities of
the system running the app).

I'm not familiar with Anchor/Dock as such. I've been playing a little with
them, but it seems to me, that they only stretch/schrink the controls in
width. I can't seem to get them to do the same in height and that leaves me
with a app, that totally looses any kind of proportion on the form unless i
resize every control manually relative to the forms size..

Does anybody have code that can do that?? or does anybody know where i can
read about that? I have tried google, but could only find some old vb6
stuff, that i could not make heads nor tale of..

Not need to reinvent the wheel if somebody else has done this or if i simply
have not understood the Anchor/Dock properties correctly...

TIA

/Finn
--
Der er 10 slags mennesker - Dem som forstår binær og dem som ikke gør.
There are 10 kinds of people. Those who understand binary and those who
don't.
Es gibt 10 Arten von Menschen. Die, die Binär verstehen, bzw. die, die es
nicht tuhen.
 
P

Peter Duniho

Finn said:
I'm about to do a new application and so far i have only made
none-resizable forms.. I want to try to do an app, that can be resized
by the user.

I was thinking along the lines of doing a initial size config, based on
the screen resolution and then letting the user drag the screen og via
the menu select preset resolutions of the app (limited by the gfx
capablillities of the system running the app).

I don't understand the phrase "letting the user drag the screen og via
the menu select preset resolutions of the app (limited by the gfx
capablillities of the system running the app)". It doesn't appear to be
a meaningful grouping of English words.
I'm not familiar with Anchor/Dock as such. I've been playing a little
with them, but it seems to me, that they only stretch/schrink the
controls in width. I can't seem to get them to do the same in height and
that leaves me with a app, that totally looses any kind of proportion on
the form unless i resize every control manually relative to the forms
size.. [...]

Anchor and Dock definitely can affect vertical positioning and size as
well as horizontal. So you aren't using them correctly if you can only
get them to work for horizontal dimensions.

Without a concise-but-complete code example that reliably demonstrates
how things aren't working for you, it is not possible to point out your
mistake.

Pete
 
F

Finn Stampe Mikkelsen

Peter Duniho said:
Finn said:
I'm about to do a new application and so far i have only made
none-resizable forms.. I want to try to do an app, that can be resized by
the user.

I was thinking along the lines of doing a initial size config, based on
the screen resolution and then letting the user drag the screen og via
the menu select preset resolutions of the app (limited by the gfx
capablillities of the system running the app).

I don't understand the phrase "letting the user drag the screen og via the
menu select preset resolutions of the app (limited by the gfx
capablillities of the system running the app)". It doesn't appear to be a
meaningful grouping of English words.
I'm not familiar with Anchor/Dock as such. I've been playing a little
with them, but it seems to me, that they only stretch/schrink the
controls in width. I can't seem to get them to do the same in height and
that leaves me with a app, that totally looses any kind of proportion on
the form unless i resize every control manually relative to the forms
size.. [...]

Anchor and Dock definitely can affect vertical positioning and size as
well as horizontal. So you aren't using them correctly if you can only
get them to work for horizontal dimensions.

Without a concise-but-complete code example that reliably demonstrates how
things aren't working for you, it is not possible to point out your
mistake.

Pete

Hi Pete

I have found out what i did wrong so now both height and width are adjusted.
But...

It still does not affect the font size in the controls and then it will
f.ex. double a textbox in width/height, but still have the same font size
and therefore leave the control looking rediculous to the user. (IMHO)

What i ment with the section you could not understand was this..

I want to start the app with a form size set relative to the user desktop.
If user has 1280x1024 i would like to start in 1024x768. if the user has
1024x768 i would like to start in 800x600...

Secondly. If the user changes the for size using the mouse, i want the app
to change the controls proportionally correct to that. Anchor seems to be
able to do that, after i played a little more around with it, but it does
not affect the fontsize and therefore it will not change f.ex. a label
control. At least i can't seem to get it to do that, even though i have set
the anchor of that label to all 4 directions. Also a textbox f.ex. will
still use 8.25 even thogh it has been doubled or tripled in size and that
looke rediculous...

Also i would like the user to be able to select a preset formsize from a
menu and then perform the resize accordingly to that preset. this is no
problem, as soon as the above mention resize code is written...

I hope you understand me now... ;-)) So far i have no code to show you,
since i have only played a little around and mostly thought about the actual
app..

/Finn
 
P

Peter Duniho

Finn said:
[...]
It still does not affect the font size in the controls and then it will
f.ex. double a textbox in width/height, but still have the same font
size and therefore leave the control looking rediculous to the user. [...]

What is "f.ex." supposed to mean? "For example"? If you must
abbreviate (and frankly, what's so far about writing the actual words?),
you should at least use the normal, universally accepted abbreviation
"e.g." instead. It took me several minutes to guess what "f.ex." might
mean, and even now I'm not 100% sure of it.

As far as the font issue goes, your observation is accurate. Only the
dimensions of the controls themselves are changed, not the font size per se.

The usual approach to changing font size is for the user to change the
font scaling in the display control panel. This in fact causes all
sorts of other problems though with respect to auto-scaling the form
dimensions to fit the font. It's basically the same problem you're
running into, but from the other direction.

I believe you may find it useful to consider writing your application
using WPF rather than the Forms API. In particular, I believe that with
WPF you can scale the entire grid for the window, in which your controls
are contained, and they all get scaled uniformly together.

Unfortunately, I'm not a WPF expert myself and so I only have a vague
idea of how you'd go about doing that. But if you spend some time with
the WPF design tools and code, I think you'll be able to figure it out.

Assuming WPF works the way I remember it, you should be able to address
all of your goals using that technique.

Pete
 
F

Finn Stampe Mikkelsen

Peter Duniho said:
Finn said:
[...]
It still does not affect the font size in the controls and then it will
f.ex. double a textbox in width/height, but still have the same font size
and therefore leave the control looking rediculous to the user. [...]

What is "f.ex." supposed to mean? "For example"? If you must abbreviate
(and frankly, what's so far about writing the actual words?), you should
at least use the normal, universally accepted abbreviation "e.g." instead.
It took me several minutes to guess what "f.ex." might mean, and even now
I'm not 100% sure of it.

As far as the font issue goes, your observation is accurate. Only the
dimensions of the controls themselves are changed, not the font size per
se.

The usual approach to changing font size is for the user to change the
font scaling in the display control panel. This in fact causes all sorts
of other problems though with respect to auto-scaling the form dimensions
to fit the font. It's basically the same problem you're running into, but
from the other direction.

I believe you may find it useful to consider writing your application
using WPF rather than the Forms API. In particular, I believe that with
WPF you can scale the entire grid for the window, in which your controls
are contained, and they all get scaled uniformly together.

Unfortunately, I'm not a WPF expert myself and so I only have a vague idea
of how you'd go about doing that. But if you spend some time with the WPF
design tools and code, I think you'll be able to figure it out.

Assuming WPF works the way I remember it, you should be able to address
all of your goals using that technique.

Pete

Hi Pete

I'm sorry for the language problems. English is not my first language..

You did understand it correctly though. I'm not at all familiar with WPF, so
for now i'm thinking either to keep on making the form rigid and not be able
to resize it or to design the form i several different sizes, take a
snapshot of that and then only be able to resize it to these pre-designed
sizes, using the saved sizing/font data for eaxh control.. In that case, i
can control the look completely.

I will have a look at WPF though... I might be able to understand it good
enough to use it..

Thanks for your patience and help..

/Finn
 
P

Peter Duniho

Finn said:
[...]
You did understand it correctly though. I'm not at all familiar with
WPF, so for now i'm thinking either to keep on making the form rigid and
not be able to resize it or to design the form i several different
sizes, take a snapshot of that and then only be able to resize it to
these pre-designed sizes, using the saved sizing/font data for eaxh
control.. In that case, i can control the look completely.

Simple may be better. In terms of offering the user less resizing
options, one thing to keep in mind is that in many applications,
resizing the window doesn't scale everything, but instead simply makes
more room for specific controls (for example, text boxes, list boxes,
etc., while buttons, checkboxes, etc. stay the same size). This can
often be just as useful a feature.

Or, of course, your suggestion about having specific sizes available to
the user may be fine too, if your goal really is to offer some kind of
scaling behavior, but at a lower development cost.

However, if you're still interested in pursuing a more robust user
experience with Forms, you may find some success by scaling the font
size dynamically as the form itself changes size.

Doing so would involve enumerating the controls in the form and
assigning a new font according to the new size. You probably would want
to have a "nominal" font size, and always scale that size according to
the current size of the form. With that, you can create a single Font
instance (or one Font instance for each different size on the form, if
the form has multiple font sizes in it...not usually a good idea from a
usability standpoint, but it sometimes happens), and then go through and
assign that font instance (or instances if appropriate) to the controls
when the form size changes.

Off the top of my head, I can't think of any other feasible approach
that would work with Forms. Specifically, AFAIK there's no practical
way to scale the rendering of a form the way you can do it in WPF. With
Forms, I think you pretty much have to be explicit about the rendering
of each control.
I will have a look at WPF though... I might be able to understand it
good enough to use it..

It's a bit of a paradigm shift, so it might take a few days to catch on
to the basics. And of course, if you're an experienced Forms
programmer, it will take some significant time before you are as good
with WPF as you are with Forms. But, once you catch on to the paradigm
difference (mainly, the more functional/declarative nature of WPF), it
should not be too hard.

Pete
 
T

Toby Allen

I have a solution for you if you still need it.
I dont have permission to post all code here,but
email me and i can help.
(e-mail address removed)
 

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