Click here to Skip to main content
11,796,275 members (77,167 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# GDI
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?
Posted 26-Jan-11 20:28pm
Edited 27-Jan-11 5:18am

1 solution

Rate this: bad
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 at 27-Jan-11 4:03am
Another 5!
SAKryukov at 4-Feb-11 18:29pm
I vote of "1"? Wow! Who is so clever?
Espen Harlinn at 26-Feb-11 4:58am
Another 5 - good work :)
SAKryukov at 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)

  Print Answers RSS
0 Maciej Los 460
1 Abhinav S 368
2 OriginalGriff 340
3 CPallini 269
4 Sergey Alexandrovich Kryukov 252
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 22 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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