【Windows】C#获取Windows屏幕尺寸
在C#中,可以使用System.Windows.SystemParameters获取有关屏幕真实状态的基本信息。
1. 获取屏幕像素:
使用SystemParameters.FullPrimaryScreenHeight和SystemParameters.FullPrimaryScreenWidth
2. 获取工作区(不包括任务栏)像素:
使用SystemParameters.WorkArea.Height和SystemParameters.WorkArea.Width
Rectangle rect=System.Windows.Forms.SystemInformation.VirtualScreen; int width=rect.Width; int height=rect.Height;
不包含任务栏的屏幕尺寸
int width = System.Windows.Forms.SystemInformation.WorkingArea.Width;
int height = System.Windows.Forms.SystemInformation.WorkingArea.Height;
包括任务栏的屏幕尺寸
int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
//1、在屏幕的右下角显示窗体 //这个区域不包括任务栏的 Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
//这个区域包括任务栏,就是屏幕显示的物理范围 Rectangle ScreenArea = System.Windows.Forms.Screen.GetBounds(this); int width1 = ScreenArea.Width; //屏幕宽度
int height1 = ScreenArea.Height; //屏幕高度
this.Location = new System.Drawing.Point(width1 - 窗体宽度, height1 - 窗体高度); //指定窗体显示在右下角 //2、在母窗体的中间显示子窗体的位置计算 waitForm.Location = new Point((this.Location.X + (this.Width - waitForm.Width) / 2),
(this.Location.Y + (this.Height - waitForm.Height) / 2));
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: c# winform取全屏幕大小
- 下一篇: C#获取屏幕大小的“简单整理”。。