现在的位置: 首页 > 综合 > 正文

C#获取当前屏幕大小或任务栏的大小,不用API.

2013年10月18日 ⁄ 综合 ⁄ 共 1883字 ⁄ 字号 评论关闭
C#获取当前屏幕大小或任务栏的大小,不用API.
2009-02-26 18:37

使用SystemInformation类就行了.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string currentScreenSize_OutTaskBar=SystemInformation.WorkingArea.Width.ToString() + "," +SystemInformation.WorkingArea.Height.ToString();

MessageBox.Show("当前的屏幕除任务栏外的工作域大小为:"+currentScreenSize_OutTaskBar);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string currentScreenSize=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString() + "," + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString();

MessageBox.Show("当前的屏幕包括任务栏的工作域大小为:"+currentScreenSize);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Size OutTaskBarSize = new Size(SystemInformation.WorkingArea.Width, SystemInformation.WorkingArea.Height);

Size ScreenSize = new Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);

Size TaskBarSize;

TaskBarSize = new Size(
                (ScreenSize.Width - (ScreenSize.Width - OutTaskBarSize.Width)),
                (ScreenSize.Height - OutTaskBarSize.Height)
                );

MessageBox.Show("任务栏大小:" + TaskBarSize.Width + "," + TaskBarSize.Height);

 

 

 

 using System.Windows.Forms;
           
获取屏幕分辨率
            int SH = Screen.PrimaryScreen.Bounds.Height;
            int SW = Screen.PrimaryScreen.Bounds.Width;  
            获取窗口居中Top和Left
            int thisH=100;
            int thisW=200;
            int SH = (Screen.PrimaryScreen.Bounds.Height - 30 - thisH) / 2;
            int SW = (Screen.PrimaryScreen.Bounds.Width - 10 - thisW) / 2;

抱歉!评论已关闭.