views:

234

answers:

1

I have a Windows Mobile project built in C#.

I have a lot of ready made forms having various controls on it, from Listviews to Editfields. When user changes orientation some elements are not refreshing correctly. For example the Listview's columns are same and doesn't accommodate the new screen width change (scrollbars appear or half of the screen is filled).

How do you handle these changes?
Do I need to call for each form these fixes by hand, or I can create some kind of global way to fix this? I would like to go with the simplest method if possible.

I would like to avoid the classic way, to add code to all of my forms. So I am looking for better ways, and I would like to see more ideas.

+1  A: 

I'm assuming that most of your controls are using a DockStyle, and that will get you 90% of the way in terms of updating the GUI on orientation changes. For the ListView, you'll have to add in some code.

You can add an event handler on Form.Resize, and there put in code to resize the ListView columns. You can tell portrait vs landscape by comparing width vs height. There's also a way to add an event handler on an actual orientation change, but it's interop and I don't remember the code offhand. Form.Resize should be sufficient for most cases.

You can check out an example here

ZaijiaN
I agree with you. I have the orientation change code for the event. I am after some module, that I can put on my project without going through each of the forms and set manually things up. What do you say?
Pentium10
Depends on how you want to do the ListView column sizing. There's ways of making it auto-size each column (similar to double-clicking on the column separator). I've written a utility method to do just that but don't have the code handy. But that'd still require you to do that for each form. Or you could add an event handler on ListView.Resize and do that code there. Either way, I can't think of a global way to automatically handle the resizing of ListView columns on orientation changes.
ZaijiaN