I am developing a .NET CF based Graphics Application, my project involves a lot of drawing images, We have decided to go for porting the application on different handset resolution.(240 X 240 , 480 X 640) etc.
How would i go onto achieve this within single solution/project?
Is there a need to create different projects based on resolutions? How would i handle common files? and i need the changes in one of the common classes to occur across all devices.
Thank you, Cronos
Don't listen to that idiot MusiGenesis. A much better way of handling different screen resolutions for Windows Mobile devices is to use forms inheritance, which can be tacked onto an existing CF application with minimal effort.
Basically, you design each form for a standard 240x320 screen. When you need to re-arrange a form for a new resolution (let's say 240x240), you add a new form to your project and have it inherit from your original 240x320 form:
public partial class frmDialog240x240: frmDialog
instead of just Form:
public partial class frmDialog240x240: Form
like usual. On your original form, you need to set the Modifiers property of each control to Protected (instead of the default Private). In the designer for your new form, you will see all of the controls on the form you're inheriting from, and you can move them and resize them as you see fit to accomodate the new screen dimensions (this will not affect the original form's layout).
When your program is running, it's easy for it to check the screen resolution of the device it's running on and create the appropriate form (a factory method is good for this). Your new form inherits everything from the old form, but uses your new custom layout.
This approach allows you to avoid code duplication, because there isn't any.
Anchoring and Docking is the most common mechanism for handling different resolutions (remember also that many devices can rotate the screen, so you need to handle changes even on a single device). Getting screen size, if needed after that, is as simple as querying the Screen object:
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int workingHeight = Screen.PrimaryScreen.WorkingArea.Height;
This code has worked for me in determining the resolution of the screen dynamically:
[DllImport("coredll.dll", EntryPoint = ("GetSystemMetrics"))]
public static extern int GetSystemMetrics(int nIndex);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private int width = GetSystemMetrics(SM_CXSCREEN);
private int height = GetSystemMetrics(SM_CYSCREEN);
I don't remember it out of the top of my head, but there is also a way to get the Screen Orientation. These would help merge some code in a single Class.
I would strongly recommend to create a single solution for all resolutions. You could have as many projects as you want under these solution. These projects could be Windows Forms Applications, Dll Library projects or Set Up Projects.
I would aim to create a single Windows Forms Application Project. I would use the above technique and read the static images from the File System. If this doesn't work for you and/or you prefer to read your images as resources, then create an 'engine' dll project, containing all the code that is common to all resolutions. Add then the output of this project as reference to as many Windows Forms Applications projects as you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With