帮忙写一个类库函数,能够获取当前计算机的像素值,用C#。谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/20 01:02:53
获取的是"桌面点击右键--属性--设置--屏幕区域"那个像素值,让像素的高度和宽度都显示到textbox中,是桌面的当前像素值。
写成函数。

class MyScreen{

private int height;
private int width;
private Rectangle rect;

public int Height
{
get { return height; }
set { height = value; }
}

public int Width
{
get { return width; }
set { width = value; }
}

public MyScreen()
{
rect = Screen.PrimaryScreen.WorkingArea;
this.Width = rect.Width;
this.Height = rect.Height;
}

}
/*
MyScreen ms = new MyScreen();
MessageBox.Show("height:" + ms.Height + " width:" + ms.Width);
*/

Windows API函数
iValue=GetDeviceCaps(hdc,iIndex)
令iIndex分别为HORZRES和VERTRES,返回值就是相应的水平像素值和垂直像素值