VB中Screen.TwipsPerPixelX和Screen.TwipsPerPixelY在Windows7中的问题
测试在XP系统下,DPI计算似乎没问题
Screen.TwipsPerPixelX=1440/DPI=1440/96=15
Screen.TwipsPerPixelX=1440/DPI=1440/120=12
Screen.TwipsPerPixelX=1440/DPI=1440/144=10
测试在Windows7下(x64,SP1),DPI为96或120时,各种主题下获取似乎都正确.
当DPI为100%(96),三种主题下,获取的值为15
当DPI为125%(120),三种主题下,获取的值为12
当DPI为150%(144),主题为Windows7(Aero)时,获取的值为15(不正确)
当DPI为150%(144),主题为经典或Basic时,获取的值为10
简单来说如果主题为Windows7默认,DPI为150%时,获取的Screen.TwipsPerPixelX和Screen.TwipsPerPixelY将不准确.
用Screen.Width / Screen.TwipsPerPixelX计算分辨率也就不正确了
上图是在Basic主题下截图
上图是在经典主题下截图
上图是在Windows7下截图
从Windows7主题切换到其他主题时,可以看到最后一个窗口的实际显示比例和另外两个不同
图片未做任何处理,使用的Print截屏
发现Screen.Width和Screen.Height两个值在Windows7主题下也有5点误差,不知道是否显示器的问题,不知道是否与显示器有关.
因为在Windows7主题下打开的窗体切换之后和其他窗体不一样大,但在125%DPI时没有这个问题,推测很可能是Windows7本身的问题.
Private Sub Command1_Click() 屏幕宽度 = Screen.Width / Screen.TwipsPerPixelX 屏幕高度 = Screen.Height / Screen.TwipsPerPixelY 窗体宽度 = Me.Width / Screen.TwipsPerPixelX 窗体高度 = Me.Height / Screen.TwipsPerPixelY 窗体工作区宽度 = Me.ScaleWidth / Screen.TwipsPerPixelX 窗体工作区高度 = Me.ScaleHeight / Screen.TwipsPerPixelY 屏幕宽度比 = Screen.TwipsPerPixelX 屏幕高度比 = Screen.TwipsPerPixelY 窗体两侧边框 = 窗体宽度 - 窗体工作区宽度 框体上下边框 = 窗体高度 - 窗体工作区高度 Text1 = "" Text1 = Text1 & "屏幕宽度" & 屏幕宽度 & vbCrLf Text1 = Text1 & "屏幕高度" & 屏幕高度 & vbCrLf Text1 = Text1 & "窗体宽度" & 窗体宽度 & vbCrLf Text1 = Text1 & "窗体高度" & 窗体高度 & vbCrLf Text1 = Text1 & "窗体工作区宽度" & 窗体工作区宽度 & vbCrLf Text1 = Text1 & "窗体工作区高度" & 窗体工作区高度 & vbCrLf Text1 = Text1 & "屏幕宽度比" & 屏幕宽度比 & vbCrLf Text1 = Text1 & "屏幕高度比" & 屏幕高度比 & vbCrLf Text1 = Text1 & "窗体两侧边框" & 窗体两侧边框 & vbCrLf Text1 = Text1 & "框体上下边框" & 框体上下边框 & vbCrLf Text1 = Text1 & "Screen.Width" & Screen.Width & vbCrLf Text1 = Text1 & "Screen.Height" & Screen.Height & vbCrLf Text1 = Text1 & "Me.Width" & Me.Width & vbCrLf Text1 = Text1 & "Me.Height" & Me.Height & vbCrLf Text1 = Text1 & "Me.ScaleWidth" & Me.ScaleWidth & vbCrLf Text1 = Text1 & "Me.ScaleHeight" & Me.ScaleHeight & vbCrLf Text1 = Text1 & "Me.Left" & Me.Left & vbCrLf Text1 = Text1 & "Me.Top" & Me.Top & vbCrLf End Sub
补充测试:
ScaleX方法测试结果也不准确
Me.ScaleX(1, 3, 1)等同于Screen.TwipsPerPixelX
Private Sub Command2_Click() Dim dpi_x As Single, dpi_y As Single, px_twip As Single dpi_x = Me.ScaleX(Screen.Width, 1, 3) / Me.ScaleX(Screen.Width, 1, 5) dpi_y = Me.ScaleY(Screen.Height, 1, 3) / Me.ScaleY(Screen.Height, 1, 5) px_twip = Me.ScaleX(1, 3, 1) Text1 = Text1 & "1像素 = " & Me.ScaleX(1, 3, 1) & " 缇" & vbCrLf Text1 = Text1 & "1像素 = " & Me.ScaleY(1, 3, 1) & " 缇" & vbCrLf Text1 = Text1 & "DPI_X = " & dpi_x & " " & vbCrLf Text1 = Text1 & "DPI_Y = " & dpi_y & " " & vbCrLf End Sub
- 点赞
- 收藏
- 分享
- 文章举报
- Screen.TwipsPerPixelX
- Vista升级Windows7存在问题,导致无限重启
- windows7 64位下Python2.7安装MySQL驱动遇到的问题
- HP电脑把windows 10 系统重装 windows7 出现的问题
- windows7 X64+VS2010安装OpenCV2.4.4时遇到的问题还有解决方法
- 某些Office 精简版 Win7运行问题(Windows7 不支持 Thinstall)
- windows7 下安装64位oracle用PL/SQL Developer连接报错问题
- Thinkpad T440安装Windows7与Ubuntu14.04双系统后启动Win7花屏问题及解决办法
- Windows7复制大文件后MD5不正确的问题之解决一法
- Windows7 中在VMware Workstation虚拟环境下的Ubuntu安装遇到的问题及解决办法记录
- 关于opencv2.4.9和VS2013在windows7下无法打开摄像头的问题的扯淡解决办法
- windows7 下安装64位oracle用PL/SQL Developer连接报错问题
- Windows7 wireshark npf 启动的问题
- Windows7下移植Qt4.8.4项目到QT5.2上时遇到的一些问题
- Windows7电脑上不去网,ipconfig查询时默认网关会出现0.0.0.0问题的解决
- MySQL5.7.19安装过程及问题(windows7 ,64)
- 完美解决Windows7 下 intel 915GM 显卡驱动问题
- Windows7 64位下SDK Manager.exe无法运行问题解决方法