Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created May 18, 2020 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusa-mochi/e8cb411ffc7b3f37611df64137cdd08e to your computer and use it in GitHub Desktop.
Save kusa-mochi/e8cb411ffc7b3f37611df64137cdd08e to your computer and use it in GitHub Desktop.
// アプリのメインウィドウ
System.Windows.Window MainWindow = System.Windows.Application.Current.MainWindow;
// DIPを物理的なピクセルに変換するための係数をもとめる。
PresentationSource MainWindowPresentationSource = PresentationSource.FromVisual(MainWindow);
Matrix m = MainWindowPresentationSource.CompositionTarget.TransformToDevice;
double dpiWidthFactor = m.M11;
double dpiHeightFactor = m.M22;
// DIPのスクリーンサイズに係数を掛け算して、スクリーンの解像度をもとめる。
double ScreenHeight = SystemParameters.PrimaryScreenHeight * dpiHeightFactor;
double ScreenWidth = SystemParameters.PrimaryScreenWidth * dpiWidthFactor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment