//: ScreenMode.cs - 设置显示模式 //: Thu 2005.08.25namespace Skyiv { using System; using System.Windows.Forms; using System.Runtime.InteropServices; class ScreenMode : Form { enum DMDO { DEFAULT = 0, D90 = 1, D180 = 2, D270 = 3 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] struct DEVMODE { public const int DM_BITSPERPEL = 0x040000; public const int DM_PELSWIDTH = 0x080000; public const int DM_PELSHEIGHT = 0x100000; public const int DM_DISPLAYFREQUENCY = 0x400000; private const int CCHDEVICENAME = 32; private const int CCHFORMNAME = 32; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)] public string dmDeviceName; public short dmSpecVersion; public short dmDriverVersion; public short dmSize; public short dmDriverExtra; public int dmFields; public int dmPositionX; public int dmPositionY; public DMDO dmDisplayOrientation; public int dmDisplayFixedOutput; public short dmColor; public short dmDuplex; public short dmYResolution; public short dmTTOption; public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)] public string dmFormName; public short dmLogPixels; public int dmBitsPerPel; public int dmPelsWidth; public int dmPelsHeight; public int dmDisplayFlags; public int dmDisplayFrequency; public int dmICMMethod; public int dmICMIntent; public int dmMediaType; public int dmDitherType; public int dmReserved1; public int dmReserved2; public int dmPanningWidth; public int dmPanningHeight; public override string ToString() { return string.Format ( "{0,4}×{1,-4} {2,2}Bits {3,3}Hz {4}", dmPelsWidth, dmPelsHeight, dmBitsPerPel, dmDisplayFrequency, dmDeviceName ); } } [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern bool EnumDisplaySettings(int lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags); ListBox lbxPels; // 构造函数 public ScreenMode() { Text = "显示属性"; lbxPels = new ListBox(); lbxPels.Parent = this; lbxPels.Dock = DockStyle.Fill; lbxPels.BeginUpdate(); DEVMODE DevMode = new DEVMODE(); for (int i = 0; EnumDisplaySettings(0, i, ref DevMode); i++) { lbxPels.Items.Add(DevMode); } lbxPels.EndUpdate(); Button btnSet = new Button(); btnSet.Parent = this; btnSet.Text = "设置显示模式"; btnSet.Dock = DockStyle.Top; btnSet.Click += new EventHandler(SetScrnMode); Button btnGet = new Button(); btnGet.Parent = this; btnGet.Text = "当前显示属性"; btnGet.Dock = DockStyle.Top; btnGet.Click += new EventHandler(GetScrnInfo); } // 设置显示模式 void SetScrnMode(object sender, EventArgs e) { if (lbxPels.SelectedItem != null) { DEVMODE DevMode = (DEVMODE)lbxPels.SelectedItem; ChangeDisplaySettings(ref DevMode, 0); } } // 当前显示属性 void GetScrnInfo(object sender, EventArgs e) { Screen scrn = Screen.PrimaryScreen; MessageBox.Show( string.Format ( "主设备: {1}{0}设备名: {2}{0}边 界: {3}{0}工作区: {4}", Environment.NewLine, scrn.Primary, scrn.DeviceName, scrn.Bounds, scrn.WorkingArea ), "当前显示属性", MessageBoxButtons.OK, MessageBoxIcon.Information ); } // 程序入口 [STAThread] static void Main() { Application.Run(new ScreenMode()); } } }
//: Thu 2005.08.25namespace Skyiv
{
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices; class ScreenMode : Form
{
enum DMDO { DEFAULT = 0, D90 = 1, D180 = 2, D270 = 3 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct DEVMODE
{
public const int DM_BITSPERPEL = 0x040000;
public const int DM_PELSWIDTH = 0x080000;
public const int DM_PELSHEIGHT = 0x100000;
public const int DM_DISPLAYFREQUENCY = 0x400000;
private const int CCHDEVICENAME = 32;
private const int CCHFORMNAME = 32; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields; public int dmPositionX;
public int dmPositionY;
public DMDO dmDisplayOrientation;
public int dmDisplayFixedOutput; public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight; public override string ToString()
{
return string.Format
(
"{0,4}×{1,-4} {2,2}Bits {3,3}Hz {4}",
dmPelsWidth,
dmPelsHeight,
dmBitsPerPel,
dmDisplayFrequency,
dmDeviceName
);
}
} [DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern bool EnumDisplaySettings(int lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode); [DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags); ListBox lbxPels; // 构造函数
public ScreenMode()
{
Text = "显示属性"; lbxPels = new ListBox();
lbxPels.Parent = this;
lbxPels.Dock = DockStyle.Fill;
lbxPels.BeginUpdate();
DEVMODE DevMode = new DEVMODE();
for (int i = 0; EnumDisplaySettings(0, i, ref DevMode); i++)
{
lbxPels.Items.Add(DevMode);
}
lbxPels.EndUpdate(); Button btnSet = new Button();
btnSet.Parent = this;
btnSet.Text = "设置显示模式";
btnSet.Dock = DockStyle.Top;
btnSet.Click += new EventHandler(SetScrnMode); Button btnGet = new Button();
btnGet.Parent = this;
btnGet.Text = "当前显示属性";
btnGet.Dock = DockStyle.Top;
btnGet.Click += new EventHandler(GetScrnInfo);
} // 设置显示模式
void SetScrnMode(object sender, EventArgs e)
{
if (lbxPels.SelectedItem != null)
{
DEVMODE DevMode = (DEVMODE)lbxPels.SelectedItem;
ChangeDisplaySettings(ref DevMode, 0);
}
} // 当前显示属性
void GetScrnInfo(object sender, EventArgs e)
{
Screen scrn = Screen.PrimaryScreen;
MessageBox.Show(
string.Format
(
"主设备: {1}{0}设备名: {2}{0}边 界: {3}{0}工作区: {4}",
Environment.NewLine,
scrn.Primary,
scrn.DeviceName,
scrn.Bounds,
scrn.WorkingArea
),
"当前显示属性",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
} // 程序入口
[STAThread]
static void Main()
{
Application.Run(new ScreenMode());
}
}
}
因为这之前 LZ 给我发私信了:无主题
qlzf11140820
41 分钟前
大侠 能不能请教个问题,c#中怎么修改DPI?或者 怎么直接Process打开显示属性->设置->高级中,直接打开高级,不打开显示属性,有没办法??我曾经用修改注册表的方式,该修改的项是改了,但不起作用,我想可能是字体要重启时安装什么的,哎,很郁闷,先谢了,这东东搞了两天时间了没解决,所以冒昧的问大侠有什么方法没啊。 wuyi8808
5 分钟前
你好,程序很长,这里贴不下,请在csdn C#版提问一下,我把程序贴给你。qlzf11140820
3 分钟前
好地 http://topic.csdn.net/u/20090909/16/79781ab8-eaa8-4e02-bdee-8e89d232e5f2.html
LZ要的是设置字体大小的那个DPI...
说实话还真不知道怎么调.
可惜lz不是vista.
我没有别的意思 ~ 之前LZ 也给我发信了,
我只找到了 获取DPI 的函数,想学习一下 ~
呵呵,我理解错 LZ 的意思了,暂时没有找到设置 DPI 的方法。
这是 Windows XP 的显示属性,有 DPI 设置项:
这是 Windows XP 的 DPI 设置窗口,不知如果不直接运行 DpiScaling.exe,如何进入:
我找到了,在 Windows Vista 下,“桌面->右键->个性化”,在左窗格中,单击“调整字体大小 (DPI)”。
int dpi = (int)rKey.GetValue("LogPixels"); rKey.SetValue("LogPixels", 120); rKey.Close();可惜不能写入,还没找到原因,你自己找找看为什么,不同的操作系统在不同的位置
不过修改后没什么效果,是不是要重启电脑
"LogPixels"=dword:00000078[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Courier 10,12,15 (8514a res)"="COURF.FON"
"MS Serif 8,10,12,14,18,24 (8514a res)"="SERIFF.FON"
"MS Sans Serif 8,10,12,14,18,24 (8514a res)"="SSERIFF.FON"
"Small Fonts (8514a res)"="SMALLF.FON"[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\GRE_Initialize]
"FIXEDFON.FON"="s8514fix.fon"
"FONTS.FON"="s8514sys.fon"
"OEMFONT.FON"="s8514oem.fon"[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\0001\Software\Fonts]
"FIXEDFON.FON"="s8514fix.fon"
"FONTS.FON"="s8514sys.fon"
"OEMFONT.FON"="s8514oem.fon"
"LogPixels"=dword:00000078[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current\Software\Fonts]
"FIXEDFON.FON"="s8514fix.fon"
"FONTS.FON"="s8514sys.fon"
"OEMFONT.FON"="s8514oem.fon"
"LogPixels"=dword:00000078这是从一个老外的网站上得到的启示,我中间还把系统搞乱了。
最后,把英文字体换成中文宋简体,并且改成了注册表格式。在我的WinXP计算机上,测试通过。96DPI的注册表,相同位置换一下就行了。C#代码不用写了吧,楼主分段复制进你原来的程序就行了。