Re: Form Resizing Nightmare.
I take it you want the form to keep the same aspect ratio (proportion of height to width). Otherwise you could just maximize the form, couldn't you?
It's not too difficult to do:
1. Calculate the aspect ratio (height/width) of the form.
2. Get the current screen size (or screen working area size, i.e. the area above the Taskbar, whichever you prefer). Calculate the aspect ratio (height/width) of the screen.
3. If the form aspect ratio is more than the screen aspect ratio, that means the form is taller and narrower than the screen. So:
- set the form height equal to the screen height.
- calculate the new width of the form (new form height / form aspect ratio).
4. If the form aspect ratio is less than that of the screen, it means the form is wider and flatter than the screen. In that case:
- set the form width equal to the screen width.
- calculate the new height of the form (new form width * aspect ratio).
In fact it takes a lot less lines of code than it does to describe it, but maybe you'd like to work it out for yourself and save your boss a few pennies:).
BB
Re: Form Resizing Nightmare.
Thanks for your reply.
The difficulty I am having is that certain elements of the form have a fixed left / top location and I have no idea how to have that changed dependent on the screen resolution. I know I should have developed in a lower resolution :(
Re: Form Resizing Nightmare.
Have you tried positioning all the controls using their Anchor property? Anchoring is easiest in the designer but you can also do it in code for example:
Code:
Button1.Anchor = AnchorStyle.Left Or AnchorStyle.Top Or AnchorStyle.Right
This example will keep the button a constant distance from the top but it will scale the button horizontally if the form size changes. I think I got the syntax right but check!
An alternative would be to put some or all of your controls into a TableLayoutPanel. If you dock the TLP into the form and dock each control into a cell of the TLP, all the controls will scale in proportion to the form. If you do that, you may also want to scale the fonts appropriately too. You could alternatively use anchoring to position the controls relative to their cell boundaries. You can also spread a control across multiple cells e.g. some controls could be 3 columns wide, others 1.
If this doesn't help you, maybe you should post an image of your form with some annotations to show what behaviour you would like to get.
BB
Re: Form Resizing Nightmare.
I, too, would look at anchoring, as that will solve most of your problems. However, if the form gets crushed down far enough, anchoring will still result in problems. That generally isn't an issue if the form is full screen, but becomes an issue if the form is in a window that can be sized dynamically. The reason is that no screen is all that small anymore, whereas a window can be shrunk down to unreason. Still, paying attention to the achnoring will make even that part work as well as possible.
The easiest way to go about testing an anchoring scheme is to make the form sizeable, set the anchoring, then test stretching and shrinking the form to see what happens.