2019/05/21

[C#] WPF Set App Window Full Screen

之前(這篇)有寫到怎麼抓螢幕的尺寸,為了讓App 可以在不同螢幕尺寸下都能保持全螢幕,可以用以下寫法。
程式碼如下:
  1. // get screen size
  2. screen_h = System.Windows.SystemParameters.PrimaryScreenHeight;
  3. screen_w = System.Windows.SystemParameters.PrimaryScreenWidth;
  4.  
  5. // set app window full screen
  6. System.Windows.Application.Current.MainWindow.Height = screen_h;
  7. System.Windows.Application.Current.MainWindow.Width = screen_w;
  8. System.Windows.Application.Current.MainWindow.Left = 0;
  9. System.Windows.Application.Current.MainWindow.Top = 0;
  10.  
  11. // set background image
  12. MainImage.Height = screen_h;
  13. MainImage.Width = screen_w;


END

沒有留言:

張貼留言