古詩詞大全網 - 個性簽名 - 如何得到當前屏幕是landscape模式 還是portrait模式

如何得到當前屏幕是landscape模式 還是portrait模式

實驗發現,通過System.Windows.Forms.SystemInformation.VirtualScreen.Height和 System.Windows.Forms.SystemInformation.VirtualScreen.Width在帖子中描述的模式中是可以獲得到當前屏幕寬度和高度的變化,並且在這種模式下也可以重新設定winform窗口的高度和寬度並且能夠生效,但是對於wpf窗口在這種模式下更改窗口的高度和寬度卻沒有任何作用。

為什麽WPF窗口在這種模式下更改窗口的寬度和高度沒有作用呢?

下面是代碼:

public MainWindow()

{

InitializeComponent();

//this.TopMost = true;

this.Topmost = true;

this.ShowInTaskbar = true;

this.ResizeMode = ResizeMode.CanResize;

this.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;

this.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;

}

private void ResetWndSize(object sender, EventArgs e)

{

//this.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;

//this.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;

}

private void ResetWindowSizeBtn(object sender, RoutedEventArgs e)

{

this.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;

this.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;

}

另外,如果想要壹個wpf desktop應用程序顯示在windows8 start頁面之上可以按照如下步驟:

1 創建壹個wpf應用程序

2 將topmost和showintaskbar屬性都設置為true

3 為應用程序添加mainfest文件並將uiAccess='true'

4 編譯程序

5 打上數字簽名

6 將程序拷貝到系統盤program file目錄下

7 運行程序

8 切換到windows8 start頁面,此時會發現您的程序會顯示在其上,如帖子中圖片所示。