2019/05/21

[C#] WPF Set App Window Full Screen

之前(這篇)有寫到怎麼抓螢幕的尺寸,為了讓App 可以在不同螢幕尺寸下都能保持全螢幕,可以用以下寫法。
程式碼如下:
// get screen size
screen_h = System.Windows.SystemParameters.PrimaryScreenHeight;
screen_w = System.Windows.SystemParameters.PrimaryScreenWidth;

// set app window full screen
System.Windows.Application.Current.MainWindow.Height = screen_h;
System.Windows.Application.Current.MainWindow.Width = screen_w;
System.Windows.Application.Current.MainWindow.Left = 0;
System.Windows.Application.Current.MainWindow.Top = 0;

// set background image
MainImage.Height = screen_h;
MainImage.Width = screen_w;


END

沒有留言:

張貼留言