Click here to Skip to main content
Rate this: bad
good
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 21:28pm
Bezawit460
Edited 27-Jan-11 6:18am
v2

1 solution

Rate this: bad
good
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 -- all that problems are already well solved, including zoom and aspect ratio. Also, performance is way too superior compared to Forms.
 
Good luck.
—SA
  Permalink  
v4
Comments
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.
--SA

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
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