100分求问!!winform编写的窗口程序,如何在win7下忽略高DPI设置,不跟随其放大放大?
现在请问,winform编写的程序,如何能忽略该设置,不随其放大而变化?
[解决办法]
我之前也遇到过,没解决。、帮顶~~~~~~~~~~~~
[解决办法]
我刚试了下.所有程序都变了.有些问题还是随大流的好.
[解决办法]
以前遇到过,好在设备都是自己的,可以自己设置,就没再去深究。
不知道能不能修改下设置尺寸的度量单位。
记得以前做网页的时候,文字大小的单位有一个是像素。
设置成其他单位时,则根据浏览器的设置显示大小不一样。
[解决办法]
可以尝试下TableLayoutPanel,把控件放到格子里。
[解决办法]
DPI适应处理方式:
1.所有设置了BackgroundImage的控件背景图 BackgroundImageLayout 属性设置为Stretch
2.窗体打开后获取DPI系数
private void Form1_Load(object sender, EventArgs e)
{
//获取系统DPI
try
{
SetProcessDPIAware(); //重要
IntPtr screenDC = GetDC(IntPtr.Zero);
int dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX);
int dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY);
CommonInfo.scaleUIX = dpi_x / 96.0;//横向系数
CommonInfo.scaleUIY = dpi_y / 96.0;//纵向系数
ReleaseDC(IntPtr.Zero, screenDC);
}
catch (Exception)
{
//throw;
//没有管理员权限就获取不到了
}
}
/*----------------------------------------获取系统DPI-----------------------------------------------------*/
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateDC(
string lpszDriver, // driver name
string lpszDevice, // device name
string lpszOutput, // not used; should be NULL
Int64 lpInitData // optional printer data
);
[DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(
IntPtr hdc, // handle to DC
int nIndex // index of capability
);
[DllImport("user32.dll")]
internal static extern bool SetProcessDPIAware();
const int DRIVERVERSION = 0;
const int TECHNOLOGY = 2;
const int HORZSIZE = 4;
const int VERTSIZE = 6;
const int HORZRES = 8;
const int VERTRES = 10;
const int BITSPIXEL = 12;
const int PLANES = 14;
const int NUMBRUSHES = 16;
const int NUMPENS = 18;
const int NUMMARKERS = 20;
const int NUMFONTS = 22;
const int NUMCOLORS = 24;
const int PDEVICESIZE = 26;
const int CURVECAPS = 28;
const int LINECAPS = 30;
const int POLYGONALCAPS = 32;
const int TEXTCAPS = 34;
const int CLIPCAPS = 36;
const int RASTERCAPS = 38;
const int ASPECTX = 40;
const int ASPECTY = 42;
const int ASPECTXY = 44;
const int SHADEBLENDCAPS = 45;
const int LOGPIXELSX = 88;
const int LOGPIXELSY = 90;
const int SIZEPALETTE = 104;
const int NUMRESERVED = 106;
const int COLORRES = 108;
const int PHYSICALWIDTH = 110;
const int PHYSICALHEIGHT = 111;
const int PHYSICALOFFSETX = 112;
const int PHYSICALOFFSETY = 113;
const int SCALINGFACTORX = 114;
const int SCALINGFACTORY = 115;
const int VREFRESH = 116;
const int DESKTOPVERTRES = 117;
const int DESKTOPHORZRES = 118;
const int BLTALIGNMENT = 119;