C# 调整分辨率,主要是用在网吧里面,有几种配置的机子。统一调成显示器最大的分辨率。
时间:2010-11-09 来源:胖子黎
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resolution;
using System.Collections;
namespace Resolution
{
public class Display
{
//public DEVMODE getResolution();
//public List<DEVMODE> getAllResolution();
public Resolution.DEVMODE devMode = new Resolution.DEVMODE();
public Resolution.DMDO dmdo = new Resolution.DMDO();
public Resolution resolution = new Resolution();
Resolution.DEVMODE dm = new Resolution.DEVMODE();
public readonly int[] disPlay = new int[400];
int count = 0;
public Display()
{
List<Resolution.DEVMODE> allMode = new List<Resolution.DEVMODE>();
allMode = resolution.getAllResolution();
foreach (Resolution.DEVMODE dm in allMode)
{
disPlay[count] = dm.dmPelsWidth;
count++;
}
//找出里面支持最大分辨率
}
public int MaxWidth()
{
int max = 800;
foreach (var item in disPlay)
{
if (item > max)
{
max = item;
}
}
return max;
}
public int DisplayCurrent()
{
dm = resolution.getResolution();
int x = dm.dmPelsWidth;
return x;
}
public void SetRosulution(int width)
{
int height = 0;
switch (width)
{
case 1920:
height = 1080;
break;
case 1680:
height = 1050;
break;
case 1280:
height = 1024;
break;
}
resolution.setResolution(width, height, 60);
}
}
class Program
{
static void Main(string[] args)
{
Display dis = new Display();
int x = dis.MaxWidth();
int y = dis.DisplayCurrent();
if (x != y)
{
dis.SetRosulution(x);
}
}
}
}