Problems while Changing Screen Orientation

S

Saurabh

Hi,
Can anyone please tell me any other way(s) to change the screen orientation.
Currently, What I did is:

1) Develop the UI based on a particular screen orientation ( portrait -
240X320).
2) In the resize event of every page, I found the ratio of height for the
current clientrectangle height to 320 and similar ratio for width.
i.e heightratio = this.clientrectangle.height/288 ( and not 320 because 320
is overall width and 288 is the client rectangle width that is there in my
app.)
widthratio = this.clientrectangle.width /240

3) I multiplied the bounds of each control with the height and width ratio
as in :
label1.bounds = new size((int)Math.Round(WidthRatio * x),
(int)Math.Round(HeightRatio * y))

With this, the orientation is changing but there is a lot of overlap between
the controls because of approximate results. Also, this approach is generic
i.e. independent of any resolution and orientation. Is there any better way
out?

Secondly, When we resize any form, then all the forms which are cached also
get resized. This causes a lot of overhead. Can we stop that.

Please help

Saurabh
 
G

Gérard Materna

Hi,

Check this :
http://www.devx.com/wireless/Article/21590

The approach is to create 2 forms (one vertical 246x318 and one horizontal
326x246) and then copy the InitializeComponent() to two methods

a.. Private Sub LandscapeMode()
a.. Private Sub PortraitMode()

and then switch between the 2 orientations in the Resize event of the form :

Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Resize
If (Screen.PrimaryScreen.Bounds.Width > _
Screen.PrimaryScreen.Bounds.Height) Then
' switch to landscape mode
LandscapeMode()
Else
' switch to portrait mode
PortraitMode()
End If
End Sub

The incovenience is that it is not independant of the resolution... Maybe
something between the 2 approaches : one form vertical, one horizontal and
then scale for the resolution?

Hope this helps,
Gérard.
 
S

Saurabh

Thanks for your reply.
This approach would bound me to just 2 resolutions i.e.
for portrait - 240X320 and for landscape 320X240. because I will be
hardcoding the size and location of controls......
What if some other resolution comes in picture........
say 480 X 320 or so.............
How will I counter that situation.............
 
R

Robert Levy [MS]

What you really want is Docking/Anchoring support for controls like .NET has
for desktop apps. That feature is not in .NET CF v1 but it will be in v2.
Depending on your timeline, you may want to consider working with the beta
version of VS 2005 and CF v2.

If that's not an option, then you will have to implement your own algorithm
for sizing and positioning controls. I'd recommend an approach that mimics
docking/anchoring (maintain distance between the selected sides of a control
and its parent).

--
Robert Levy
Program Manager
Mobile Devices Product Group
http://blogs.msdn.com/windowsmobile

This posting is provided "AS IS" with no warranties, and confers no
rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top