如何保持用户控件的宽高比? [英] How to keep the aspect ratio of a UserControl?

查看:203
本文介绍了如何保持用户控件的宽高比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个想法如何保持高度/宽度比1:一个用户控件的1

Does anyone have an idea how to keep the Height/Width Ratio 1:1 of a UserControl?

例如。如果高度>宽度,宽度和放大器;高度将有相同的大小,反之亦然。

E.g. if Height > Width, Width & Height will have the same size and vice versa.

推荐答案

我不知道这会工作,但如果你注册一个处理对于 时,SizeChanged 并在那里把你的代码事件保持纵横比为1:1。

I'm not sure this will work, but if you register a handler for the SizeChanged event and in there put in your code keep the aspect ratio 1:1.

SizeChangedEventArgs 参数有旧的尺寸和新的大小,以便您可以检查哪些改变并相应地更新等。

The SizeChangedEventArgs argument has the old size and the new size so you can check which has changed and update the other accordingly.

您可能需要引入一个保护变量,这样你就不会得到时,SizeChanged 事件更新身高的结果宽度

You might need to introduce a guard variable so that you don't get a cascade of SizeChanged events as a result of updating the Height or Width.

这篇关于如何保持用户控件的宽高比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆