一、背景

  在PC机上显示正常,在高分辨率下的Pad上,显示出现问题:

    1、显示在屏幕最右端的窗体(控件)显示不出来;

    2、截图时,被截图的界面字体文字变大,界面因此显示不全。

二、解决方法:

  方法一:WPF上使用WPF方式获取屏幕大小,而不是Winform的获取屏幕大小的方式。

                //Size primarySize = Screen.PrimaryScreen.Bounds.Size;
double dWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
double dHeight = System.Windows.SystemParameters.PrimaryScreenHeight;

  方法二:Winform解决方法:

  1、设置窗体的背景图片方式改为可缩放方式(Zoom): BackgroundImageLayout = ImageLayout.Zoom;

  2、依据DPI扩展拷贝图片的大小,设置拷贝的图片的DPI(bmp的SetResolution方法)

BackgroundImage = GetDestopImage();
BackgroundImageLayout = ImageLayout.Zoom; private Image GetDestopImage()
{
float rate = dpi / ;
Rectangle rect = Screen.GetBounds(this);
Size sz = new System.Drawing.Size();
sz.Width = (int)(rect.Size.Width * rate);
sz.Height = (int)(rect.Size.Height * rate);
Bitmap bmp = new Bitmap(
sz.Width, sz.Height, PixelFormat.Format32bppArgb);
bmp.SetResolution(dpi, dpi);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(, , , , sz);
//IntPtr gHdc = g.GetHdc();
//IntPtr deskHandle = NativeMethods.GetDesktopWindow(); //IntPtr dHdc = NativeMethods.GetDC(deskHandle);
//NativeMethods.BitBlt(
// gHdc,
// 0,
// 0,
// Width ,
// Height,
// dHdc,
// 0,
// 0,
// NativeMethods.TernaryRasterOperations.SRCCOPY);
//NativeMethods.ReleaseDC(deskHandle, dHdc);
//g.ReleaseHdc(gHdc);
//bmp.Save("test.png");
return bmp;
}

  3、修改拷贝内容位置信息

        private void DrawLastImage()
{
float rate = dpi / ;
int reWidth = (int)(Width * rate);
int reHeight = (int)(Height * rate);
using (Bitmap allBmp = new Bitmap(
reWidth, reHeight, PixelFormat.Format32bppArgb))
{
allBmp.SetResolution(dpi,dpi);
using (Graphics allGraphics = Graphics.FromImage(allBmp))
{
allGraphics.InterpolationMode =
InterpolationMode.HighQualityBicubic;
allGraphics.SmoothingMode = SmoothingMode.AntiAlias;
allGraphics.DrawImage(
BackgroundImage,
Point.Empty);
DrawOperate(allGraphics);
allGraphics.Flush(); Rectangle reSelectImageRect = new Rectangle();
reSelectImageRect.X = (int)(SelectImageRect.X * rate);
reSelectImageRect.Y = (int)(SelectImageRect.Y * rate);
reSelectImageRect.Width = (int)(SelectImageRect.Width * rate);
reSelectImageRect.Height = (int)(SelectImageRect.Height * rate);
Bitmap bmp = new Bitmap(
reSelectImageRect.Width,
reSelectImageRect.Height,
PixelFormat.Format32bppArgb);
bmp.SetResolution(dpi, dpi);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(
allBmp,
,
,
reSelectImageRect,
GraphicsUnit.Pixel); g.Flush();
g.Dispose();
_image = bmp;
}
}
}

  4、获取DPI代码:

        public static float getLogPiex()
{
float returnValue = ;
try
{
RegistryKey key = Registry.CurrentUser;
RegistryKey pixeKey = key.OpenSubKey("Control Panel\\Desktop");
if (pixeKey != null)
{
var pixels = pixeKey.GetValue("LogPixels");
if (pixels != null)
{
returnValue = float.Parse(pixels.ToString());
}
pixeKey.Close();
}
else
{
pixeKey = key.OpenSubKey("Control Panel\\Desktop\\WindowMetrics");
if (pixeKey != null)
{
var pixels = pixeKey.GetValue("AppliedDPI");
if (pixels != null)
{
returnValue = float.Parse(pixels.ToString());
}
pixeKey.Close();
}
}
}
catch(Exception ex)
{
returnValue = ;
}
return returnValue;
}

C#:涉及DPI的高分辨率下的显示问题的更多相关文章

  1. 在不同DPI屏幕环境下,让图标显示的尺寸保持不变,使用 LoadImage() 加载图标

    之前写过的一个客户端程序中,需要在状态栏上显示图标: 我当时使用的是:HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName); 在DPI:125 ...

  2. 完美解决,浏览器下拉显示网址问题 | 完美解决,使用原生 scroll 写下拉刷新

    在 web 开发过程中我们经常遇到,不想让用户下拉看到我的地址,也有时候在 div 中没有惯性滚动,就此也出了 iScroll 这种关于滚动条的框架,但是就为了一个体验去使用一个框架好像又不值得,今天 ...

  3. JFreechart在linux下不显示及中文乱码问题

    一.使用JFreeChart建的报表,在window下能正常显示,但是放到linux下就报错,而且有时候会把tomcat挂掉, 原因是jfreechart的在linux系统中需要访问java awt库 ...

  4. css 图片内容在不同分辨率下居中显示(演示的图片宽度是1920px,当图片宽度大于显示屏的宽度时)

    1.img 图片内容在不同分辨率下居中显示(如果隐藏多余,在img外面套一个div  设定overflow: hidden.div的大小就是img显示区域的大小) <!DOCTYPE html& ...

  5. Linux下grep显示前后几行信息

    Linux下grep显示前后几行信息 标准unix/linux下的grep通过下面參数控制上下文 grep -C 5 foo file 显示file文件里匹配foo字串那行以及上下5行grep -B ...

  6. Linux下中文显示乱码问题

    Linux下中文显示乱码问题 输出编码选utf-8 然后文件本身编码也要是utf-8

  7. DataGridView单元格内容自动匹配下拉显示

    页面显示数据使用的控件是ComponentFactory.Krypton.Toolkit中的KryptonDataGridView控件.在指定“商品”单元格中需要根据用户输入内容自动匹配数据库中商品信 ...

  8. win7系统扩展双屏幕时,如何在两个屏幕下都显示任务栏

    扩展屏幕下都显示任务栏!!! win7系统本身无法设置该功能(目前我是不知道) 但可以下载第三方软件来解决该问题. 第一步:Dual Monitor Taskbar 下载软件 下载链接:http:// ...

  9. qt如何实现一个渐隐窗口呢(开启的时候他是从上往下渐渐显示)

    qt如何实现一个渐隐窗口呢?就是比如说开启的时候他是从上往下渐渐显示的,关闭的时候从下往上渐渐小时的http://stackoverflow.com/questions/19087822/how-to ...

随机推荐

  1. HDU 5762

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tot ...

  2. Linux关闭休眠和屏保模式

    本人因为特殊需求,想让某台Linux主机始终显示某个程序,显示器不能关机或者休眠或进入屏保模式. 环境:Ubuntu 11.10 最小化模式安装并安装有轻量级桌面openbox(非gnome).因为X ...

  3. AspxSpy2014 Final

    受bin牛委托修改并发布,版权归bin牛所有. Bug/建议提交:zcgonvh@rootkit.net.cn 祝各位马年大吉,财源滚滚. 免责声明: 本程序只用于管理员安全检测,使用前请注意环境与法 ...

  4. eclipse中如何修改dynamic web module version

    java项目中,若切换服务器,经常会涉及到动态web模块版本的问题.      比如:新建了web项目,开始使用tomcat服务器,但是后来使用jboss服务器,就会出现:Project facet ...

  5. EF框架中加子类后出现列名 'Discriminator' 无效问题

  6. JSCH实现文件上传的代码实例

    package com.vcredit.ddcash.monitor.sendmail; import java.io.File;import java.io.FileInputStream;impo ...

  7. # 20145334赵文豪 《Java程序设计》第7周学习总结

    20145334赵文豪 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 13.1.1时间的度量 1.格林威治时间(GMT):参考太阳到达最高点,有时间误差. 2 ...

  8. Interface => IDataErrorInfo

    Introduction to common Interfaces IDataErrorInfo Provides the functionality to offer custom error in ...

  9. java 虚拟机--新生代与老年代GC

    Heap: JVM只有一个为所有线程所共享的堆,所有的类实例和数组都是在堆中创建的. Method area: JVM只有一个为所有的线程所共享的方法区.它存储类结构,例如运行时常量池,成员和方法数据 ...

  10. Python中的函数修饰符@

    首先,什么是函数修饰符?函数修饰符就是对原有函数做一层包装.比如有以下两个函数: 复制代码 def func1(): print 'I am function func1' def func2(): ...