Windowsストアアプリ入門 vol81:画面サイズを取得する

月曜日 , 5, 11月 2012 Leave a comment

 Windowsストアアプリケーションでディスプレイサイズの合わせて表示を調整したい場合があります。

 その場合はディスプレイサイズの変更はSizeChangedイベントで取得します。

 

 あわせてDPIを取得するコードも紹介します。

 

        public MainPage()
        {
            this.InitializeComponent();

            this.SizeChanged += MainPage_SizeChanged;

            DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;
        }

        void DisplayProperties_LogicalDpiChanged(object sender)
        {
            this.dpiText.Text = DisplayProperties.LogicalDpi.ToString();
        }

        void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.widthText.Text = e.NewSize.Width.ToString();
            this.heightText.Text = e.NewSize.Height.ToString();
            this.dpiText.Text = DisplayProperties.LogicalDpi.ToString();
        }

 

 

 

サンプルコード

 

 実行可能なサンプルコードは以下、シミュレーターでいろいろサイズを変えて試してみてください。

 DisplaySizeSample


Please give us your valuable comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください