views:

525

answers:

5

I have a .NET 2.0 application that runs on Compact Framework. It has a bunch of different forms that were all originally designed to run on a specific device with a specific screen resolution. I'm now looking to get this application to run on some other devices that have very different screen resolutions (some have completely opposite aspect ratios where the screen is now taller than it is wide). My question is how can I change my forms to look good on these other screens?

This is a bit different from designing forms on the full framework since I have to design these forms to take up the full screen since the screens are so small. I've thought about creating separate forms for each type of screen orientation (e.g. MyForm_Wide.cs, MyForm_Tall.cs, etc). I'd like to be able to reuse the non-designer generated code that contains a lot of business logic that is tied to the UI controls. Maybe I could somehow use partial classes to make this happen (e.g. MyForm.cs somehow gets compiled into MyForm_Wide.Designer.cs, etc). I'd really like to avoid specifically compiled versions for each screen orientation. Another approach I've thought about is trying to rearrange some controls at runtime based on the determined screen size.

What do you guys think?

A: 

We use the Orientation Aware Control framework by Clarius. It solves the problem of not only form factor, but also on devices that support it, change of orientation (screen rotation).

Perhaps the most distinctive aspect of mobile development with regards to traditional desktop development is the need to support an ever increasing range of device form factors.

For expert mobile developers it's no news that designing mobile applications that support multiple form factors, resolutions and screen orientations is a non-trivial, time-consuming and challenging endeavor. It's also generally evident that the built-in docking and anchoring features in .NET Compact Framework v2.0 is far from being sufficient.

The Orientation Aware Control allows designing and coding a single control or form with multiple layouts or skins that are automatically applied at run-time (and design-time) according to the available form factor, resolution and orientation. Its outstanding Visual Studio forms and user control designer integration and zero-code adaptive UI behavior make the Orientation Aware Control a must-have companion for any mobile shop targeting multiple devices, bringing back the productivity you need to focus on growing your business.

Bryan Batchelder
That is a pretty interesting looking framework. I think if I was starting a new project I'd look into using that, but for my existing project I have too much existing code to switch over at this point.
Jason
A: 

Since the c# designers are very 'pixel-orientated' there is no easy way to convert your forms.

I don't know how much effort you want to put into this, but if you have a lot of time and want a really flexible solution I suggest you should use some kind of layout manager that supports flow layouts, border layouts etc.

Of course the original c# designers won't be much help designing these flexible layout-managed forms.

But using a layout manager might slow down the initial display of your form. If you want really high speed form display you will have to calculate all positions of all controls on your form before you show the form. Rearrange the controls and display your form - this is however a lot of coding and not very flexible regarding gui changes.

Simon Ottenhaus
+1  A: 

You should probably set your main forms 'AutoScaleMode' property to 'DPI'.

Then, its a matter of using anchors and docking on your particular controls on the forms. If you do it this way, the compact framework will keep things where you thought they'd be.

Also, can change the 'Form Factor' property of the form to see how your form would look on mobile devices of different sizes and shapes.

Mike D
This article should give you some pointers on how to use Anchors and docking: http://msdn.microsoft.com/en-us/library/ms229649.aspx
tomlog
My forms already use DPI scaling and I'm tweaking the anchors and docking as needed. However, I still have a couple issues: For higher resolution screens the controls don't look properly laid out (e.g. text boxes span the whole width of the screen when they really don't need to; on the lower res screens they do need to). Also, for devices that have different aspect ratios this doesn't work at all as I know how controls that are very wide but there is now a vertical scroll bar that is needed to scroll down.
Jason
A: 

I think I've figured out what I want to do. For some reason even on my high res devices the DPI still shows up as 96 according to the WinForms API so the auto scaling isn't doing anything. Instead, if I manually call Scale on my controls I get them to scale out exactly how I want. Now, this doesn't completely solve my problem in scenarios where I don't want to do any scaling but I do want to reorganize my controls if the screen is in the opposite aspect ratio than what I originally designed for. For that case, I think I'm going to look at using different layout panels (e.g. FlowLayoutPanel and TableLayoutPanel) to hopefully organize the controls appropriately.

Hopefully this will help any future Googler...

Jason
nice work trooper.
Mike D
Just to add some additional info here, the FlowLayoutPanel and TableLayoutPanel that I mentioned previously are not available on the compact framework (I should have seen that one coming). All that I really want is a way to get VS's designer to basically generate multiple InitializeComponent methods for different resolutions. Then in my form's constructor I can simply choose which one to call. I can't find a way to do this, unfortunately. Maybe I need to look into creating a VS addin that does this...
Jason
I found the following Microsoft article on this topic:http://msdn.microsoft.com/en-us/library/ms838174.aspxIt's meant for VS .NET 2003, but it doesn't seem like they've really addressed this issue in any subsequent release. They're basically saying that you should create Portrait and Landscape methods and copy the VS designer generated code for each layout into the appropriate method. I'm sort of following this approach except I'm copying the entire InitializeComponent methods since it is too difficult to just pick the size/position code out.
Jason
A: 

The 'Auto Size' property on labels messes up when switching between form factors too - btw - so I keep it set to false.

Mike D