当前位置:网站首页>WPF动态创建的window窗体dpi异常问题
WPF动态创建的window窗体dpi异常问题
2022-04-22 00:57:00 【SarznLiu】
项目中有一个需求,需要在WPF的主窗体中点击按钮创建一个子窗体,子窗体的位置需要跟随父窗体移动,在多屏幕且各个屏幕dpi不同的情况下,动态创建的窗体在创建时的初始dpi是程序运行时所在屏幕(简单来说,比如有屏幕1、2,在屏幕1上双击图标运行了程序,然后将程序拖到屏幕2上去,屏幕1就是程序运行的初始屏幕,动态创建的子窗体dpi初始值就与屏幕1的dpi相同),此时再根据坐标移动子窗体时就会出现坐标计算错误,而且该问题仅在初始时出现。
解决办法:在动态创建子窗体后,子窗体需要先调用show方法,然后获取此时子窗体的缩放比
var source = PresentationSource.FromVisual(myWindow);
if (source != null)
dpiRatio = source.CompositionTarget.TransformToDevice.M11;
还要用同样方法获取到此时父窗体的dpi,然后根据两个dpi计算对应的坐标
版权声明
本文为[SarznLiu]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liusarzn/article/details/124299862
边栏推荐
- Pytoch installation and troubleshooting of groupspatialsoftmax errors
- Faster R-CNN代码详解 标注数据形状
- Boutique: thousand word long text teaches you to use byte beating volcanic engine imagex
- Yibao IPO, farmer Shanquan panicked?
- 观测云登陆阿里云计算巢,共建ISV新生态
- From concept to realization, how does smart home come into our life step by step
- 在setTimeout里设置倒数5秒计时的方法
- 简单理解变量的结构赋值
- While hoarding goods, it's time to recognize cans again
- The middle order traversal of binary tree
猜你喜欢

. net core enterprise wechat web page authorization login

A comprehensive analysis of the application of histogram

Solve the problem that the idea web project does not have small blue dots

We sincerely invite you to sign up for the first openharmony developer growth plan sharing day

3D 沙盒游戏之人物的点击行走移动

Public testing, exclusive, penetration testing, picking up ragged tips

OBS录制的avi能够被imageJ打开吗?

Redis personal notes: redis application scenario, redis common commands, redis cache breakdown and penetration, redis distributed lock implementation scheme, spike design idea, redis message queue, Re

Matlab: simulate the control system and use ode45 to solve the LC circuit

精品:千字长文教你使用字节跳动的火山引擎ImageX
随机推荐
[observation] let the energy industry "dance with elephants", and the Chinese system build a digital base with hard core strength
OBS录制的avi能够被imageJ打开吗?
[audio and video] RTCP
Addition, deletion, modification and query of advanced MySQL data (DML)
Oceanbase 和 TiDB 粗浅对比之 - 执行计划
Prometheus 的使用
Observe cloud landing in Alibaba cloud computing nest and build a new ISV ecosystem
精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
[zeele_tech] Introduction to ROS / ROS 2
安装包签名检测
Use of Prometheus
The WPF control created through WinForm control cannot be input
腾讯团队实力打造flutter入门教程,1-3年Android开发工程师面试经验分享
Tencent Android development interview experience, HR's words pierced my heart
Shell 集群免密关机
Hold these five points! On the job postgraduate entrance examination can also go ashore!
Huawei has launched the new BMW 7 Series in the application market to create a luxury peak smart travel experience
GridData 布局说明
[high concurrency] Why is there a strange bug problem when writing long variables on a 32-bit multi-core CPU? After reading this article, I understand!
Muduo project introduction