[C#][VB.NET]取得目前螢幕的解析度

  • 55378
  • 0
  • 2011-08-24

取得螢幕目前的解析度

 

1. 問題描述

如何取得螢幕解析度

 

2. 方法

取得螢幕目前的解析度,可以透過 Screen.PrimaryScreen Property 來達成,假如要取得工作區,可透過 Screen.PrimaryScreen.WorkingArea 達成

可以參考MSDN的說明

http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.primaryscreen.aspx

以下程式碼功能為 Button1 Click 後,顯示 MessageBox,內容為螢幕解析度

C#

        private void button1_Click(object sender, EventArgs e)
        {
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;
            MessageBox.Show("螢幕解析度為 " + screenWidth.ToString() + "*" + screenHeight.ToString());
        }

 

VB.NET

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim screenWidth = Screen.PrimaryScreen.Bounds.Width
        Dim screenHeight = Screen.PrimaryScreen.Bounds.Height
        MessageBox.Show("螢幕解析度為 " + screenWidth.ToString() + "*" + screenHeight.ToString())
    End Sub

 

 

 

執行結果