public partial class Form1 : Form
    {
public Form1()
        {
InitializeComponent();
 
            SetProcessDPIAware(); //重要
            IntPtr screenDC = GetDC(IntPtr.Zero);
            int dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX);
            int dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY);
            //_scaleUI.X = dpi_x / 96.0;
            //_scaleUI.Y = dpi_y / 96.0;
            ReleaseDC(IntPtr.Zero, screenDC);
 
        }
 
        [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;
}

获取系统DPI的更多相关文章

  1. C# API 获取系统DPI缩放倍数跟分辨率大小

    原文:C# API 获取系统DPI缩放倍数跟分辨率大小 using System; using System.Drawing; using System.Runtime.InteropServices ...

  2. WPF 获取系统 DPI 的多种方法

    原文:WPF 获取系统 DPI 的多种方法 WPF 获取系统 DPI 的多种方法 由于 WPF 的尺寸单位和系统的 DPI 相关,我们有时需要获取 DPI 值来进行一些界面布局的调整,本文汇总了一些 ...

  3. 获取系统DPI、系统显示比例等

    using System; using System.Drawing; using System.Runtime.InteropServices; namespace XYDES { public c ...

  4. ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,

    一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...

  5. Delphi编程获取系统当前进程、窗口句柄、文件属性以(转)

    Delphi编程获取系统当前进程.窗口句柄.文件属性以及程序运行状态. uses TLHelp32,PsAPI; (1)显示进程列表:procedure TForm1.Button2Click(Sen ...

  6. android 获取系统联系人 完全解析

    一.代码 1.ContactsEngine.java import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...

  7. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  8. Android 获取系统的联系人

    本文主要介绍android中怎样获取系统的联系人数据 首先打开模拟器 点击联系人图标按钮 说明系统联系人数据库是空的,打开File explorer,找到data/data下面的文件夹: 将conta ...

  9. Linux sysinfo获取系统相关信息

    Linux中,可以用sysinfo来获取系统相关信息. #include <stdio.h> #include <stdlib.h> #include <errno.h& ...

随机推荐

  1. FIS3项目构建

    概述 FIS3采取了类似CSS语法一样的配置风格,易于理解与上手.FIS3 是面向前端的工程构建工具.解决前端工程中性能优化.资源加载(异步.同步.按需.预加载.依赖管理.合并.内嵌).模块化开发.自 ...

  2. unity3d为对象添加脚本的两种方法

    首先添加一个物体,然后新建一个C#脚本.接下去有两种方法把C#脚本与物体绑定. 1.在类声明上方添加如下代码: [AddComponentMenu("a/b")] 这句话表示在该物 ...

  3. Java Jar maven 下载地址

    Java Jar maven 下载地址 https://repo1.maven.org/maven2/ 根据maven artifactid 查找相关jar

  4. ajax 上传图片

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  5. C 语言 ioctl

    /* *@author cody *@date 2014-08-12 *@description */ /* #include <sys/ioctl.h> send control and ...

  6. atitit.系统架构图 的设计 与工具 attilax总结

    atitit.系统架构图 的设计 与工具 attilax总结 1. 架构图的4个版式(标准,(左右)悬挂1 2. 架构图的层次结构(下属,同事,助手)1 3. wps ppt1 4. 使用EDraw画 ...

  7. location alias与root

    网站的根目录是:/alidata/www/webtest [root@M webtest]# tree /alidata/www/ /alidata/www/ ├── abc.html └── web ...

  8. C++语言基础(25)-C++格式化输出

    一.使用控制符控制输出格式 #include <iostream> #include <iomanip>//不要忘记包含此头文件 using namespace std; in ...

  9. mysql 两列互转

    1.mysql 一张表两列互转 UPDATE tm_position as a,tm_position as b SET a.gps_longitude = b.gps_latitude,a.gps_ ...

  10. 跑测试没有web环境的情况

    有时候 当你跑测试的main方法的时候,会有一些莫名其妙的错误,明明mave pom的包是全的,web跑起来不会报错,可是在main方法下就是报错了,这个时候引入  <dependency> ...