Click here to Skip to main content
14,241,831 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi. I am using a UserControl to display a picture. My application has a Zoom In/Zoom Out feature. I can press the Zoom Out button any
number of times and the background code I write will make sure that the left side of the picture would not leave the left side of the
UserControl it is drawn up on. This logic works fine only for a single resolution. Can I make this logic work irrespective of the device resolution?
Updated 27-Jan-11 5:18am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I've done this screen-independent layout (with and without zoom) many times and never had problems.
There are few simple rules you can check.

Look at your design-time generated form code (as C# source) and find all immediate constants of integer types. You should not find a single one that defined a size or location of any controls. Exclusions are: font size, form size — current and minimum/maximum — and padding. In other words, all controls should be docked and aligned using padding. You should do another simple check: change your form width/height drastically — layout should keep its sanity. If you should preserve aspect ratio of some elements, you should perform proper re-calculations in Resize event. Never use anchors — not only they use constants, they also tend to cause some flicker in resize. If you observe all this, you layout will tolerate screen size.

Additionally and optionally, you can read Screen size and change form size proportionally before you show it. (You can call some function with all adjustments and settings in a last line of the form constructor (right after a call to InitializeComponent()).

Forget about intellisense: what, is it difficult to see source code (from meta-data) or Help? By the way there is not SetDockStyle, there is the property Dock — don't blame your intellisense.

Alternative advice: switch to WPF, where all that problems are already well solved, including zoom and aspect ratio. Also, performance is way too superior compared to Forms.

Good luck.
Sandeep Mewara 27-Jan-11 4:03am
Another 5!
I vote of "1"? Wow! Who is so clever?
Espen Harlinn 26-Feb-11 4:58am
Another 5 - good work :)
Sergey Alexandrovich Kryukov 26-Feb-11 13:21pm
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100