2008-11-08 63 views

回答

3

在Microsoft.WindowsMo​​bile.Status有以跟蹤各種設備的性能的一類。 除了您需要的DisplayRotation之外,它還包含有關電話覆蓋範圍,未接電話數量,下次約會等等的屬性。有關更多信息,請參見msdn

您還可以添加一個事件處理程序來通知這些屬性的更改。

0

只是猜測,但我第一次嘗試是:

var rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds; 
// or var rect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; 

var ratio = rect.Width/rect.Height; 

if (ratio == 1.0) // square screen. 
if (ratio > 1.0) // landscape. 
if (ratio < 1.0) // portrait. 
+0

這是行不通的,但這是新的「var」關鍵字主要擅長隱藏否則顯而易見的問題的一個很好的例子。 – MusiGenesis 2008-11-08 12:04:17

2

將對Microsoft.WindowsCE.Forms的引用添加到您的項目中。然後你可以參考 Microsoft.WindowsCE.Forms。 SystemSettings.ScreenOrientation屬性,它會給你你所需要的。

順便提一句,你可以設置這個屬性,所以它也可以用來設置你的屏幕方向。

1

你應該添加2個Refrences到項目: Microsoft.WindowsMo​​bile Microsoft.WindowsMo​​bile.Status

,那麼你可以使用此代碼確定方向:

int orientation=Microsoft.WindowsMobile.Status.SystemState.DisplayRotation; 
if(orientation== 90 || orientation==-90 || orientation==270) //Landscape is 90 or -90 or 270 
{ 
    //your code; 
} 
else 
{ 
    //your code; 
}