winform 获取屏幕分辨率 代码
时间: 2023-09-15 15:19:37 浏览: 58
以下是获取屏幕分辨率的 WinForm 代码:
```csharp
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
```
您需要在代码文件的顶部添加以下命名空间:
```csharp
using System.Windows.Forms;
```
这里使用了 `Screen.PrimaryScreen` 属性来获取主屏幕的分辨率。如果您需要获取其他屏幕的分辨率,可以使用 `Screen.AllScreens` 属性来获取所有屏幕的信息,并选择您需要的屏幕。
相关问题
winform 获取屏幕分辨率
你可以使用 System.Windows.Forms.Screen 类中的静态属性获取当前屏幕的分辨率。具体代码如下:
```
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
```
这里,我们使用 `Screen.PrimaryScreen` 获取主屏幕,然后通过 `Bounds` 属性获取屏幕的尺寸信息。`Bounds` 属性返回一个 `Rectangle` 类型的对象,其中包含了屏幕的尺寸和位置信息,我们可以通过它的 `Width` 和 `Height` 属性获取屏幕的宽度和高度。
winform 运行时分辨率
Winform 应用程序的运行时分辨率可以通过以下代码获取:
```csharp
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
```
这将返回主屏幕的宽度和高度(以像素为单位)。您还可以使用以下代码获取当前应用程序窗口的分辨率:
```csharp
int windowWidth = this.Width;
int windowHeight = this.Height;
```
注意,窗口分辨率可能小于屏幕分辨率,因为窗口可能被最大化或调整大小。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)