一、背景

  在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. 手机触屏触摸特效javascript-TouchSwipe(依赖于jquery库)中文说明

    by 郑州seo on 2013 年 7 月 6 日 in jquery, 网站建设 with 6 Comments 最近需要做一个手机小门户网站,因为目前主流的手机都是安卓和苹果的,他们的浏览器内核 ...

  2. xshell连接本地虚拟机

    打开虚拟机输出命令ifconfig 然后使用xshell,连接这个地址即可 如果没有ip地址的话,这可以用“ifconfig eth0 ip地址 比如ifconfig eth0 192.3168.16 ...

  3. css文本溢出省略号

    .ellip{ display: block; width:200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; ...

  4. SpringMVC表单标签简介

    在使用SpringMVC的时候我们可以使用Spring封装的一系列表单标签,这些标签都可以访问到ModelMap中的内容.下面将对这些标签一一介绍. 在正式介绍SpringMVC的表单标签之前,我们需 ...

  5. php课程---练习(发布新闻)

    做一个发布新闻的页面,实现发布新闻,查看新闻,修改新闻与删除等功能 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ ...

  6. 杭电ACM 1178

    #include<stdio.h>#include<string.h>#include<math.h>#include<ctype.h>#include ...

  7. IOS第16天(5,Quartz2D雪花)

    *** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...

  8. 【iCore3 双核心板】例程二十六:MODBUS TCP实验——电源监控

    实验指导书及代码包下载: http://pan.baidu.com/s/1pKhxKd9 iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  9. symmetric multiprocessor

    https://en.wikipedia.org/wiki/Symmetric_multiprocessor_system A symmetric multiprocessor system (SMP ...

  10. HDFS的概念

    1.数据块 每个磁盘都有默认的数据块大小,这是磁盘进行数据读/写的最小单位.构建于单个磁盘之上的文件系统通过磁盘块来管理该文件系统中的块,该文件系统块的大小可以是磁盘块的整数倍.文件系统快一半为几千字 ...