一、背景

  在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. Aidl的使用步骤

    先说说Aidl传递参数类型 1.基本数据类型(除short类型) 2.String.charSequence 3.List,map 4.parcelable 第1步:定义一个*.aidl文件,ecli ...

  2. Ubuntu FTP 配置

    1. apt-get install vsftpd 2. vim /etc/vsftp.conf #禁止匿名访问 anonymous_enable=NO #接受本地用户 local_enable=YE ...

  3. JAVA中序列化和反序列化

    一般程序在运行时,产生对象,这些对象随着程序的停止运行而消失(java回收机制)但如果我们想把某些对象(因为是对象,所以有各自不同的特性)保存下来,在程序终止运行后,这些对象仍然存在,可以在程序再次运 ...

  4. Lamp下安全配置随笔

    Apache方面: 1.apache有两个指令可以输出服务器的细节,即ServerSignature和ServerTokens. 当这两个指令一起使用时,会输出apache的版本号,php的版本号,i ...

  5. js变量

    由于undefined和null两个值的比较是相等的,所以,未初始化的变量和赋值为null的变量会相等.这时,可以采用typeof变量的类型进行比较.但,建议还是养成编码的规范,不要忘记初始化变量. ...

  6. HDU4325 树状数组

    Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  7. Hibernate查询 Query Language

    1,Native SQL ->HQL->EJBQL->QBC(Query By Cretira)->QBE(Query By Example) 此排列是根据可实现功能大小排序.

  8. php数组序列化serialize与unserialize

    $arr=array('1','2','3');echo serialize($arr); //序列化 a:3:{i:0;s:1:"1";i:1;s:1:"2" ...

  9. CacheManagerUtils.java

    package com.vcredit.framework.utils; import net.sf.ehcache.Cache;import net.sf.ehcache.CacheManager; ...

  10. js树形控件

    js树形控件 ztree http://www.treejs.cn/