[英]Using 2 NumericUpDown fields to maintain Dimensions aspect ratio
I have two NumericUpDown text fields. 我有两个NumericUpDown文本字段。 They are used for Image Dimensions.
它们用于图像尺寸。 I've done it before but I don't remember how I did it.
我以前做过,但是我不记得我是怎么做的。 I've looked at over 20 related questions on here but they're not really the same question.
我看就在这里了20个相关的问题,但他们并不是真正的同样的问题。 The logic and math is totally different than what I need.
逻辑和数学与我所需要的完全不同。
Basically, numericUpDown1 is for Width and numericUpDown2 is for Height. 基本上,numericalUpDown1表示宽度,numericalUpDown2表示高度。 When the numericUpDown1 value is changed (either by using arrows or typing), numericUpDown2 must auto change as well, while maintaining the correct aspect ratio.
更改numericUpDown1值(通过使用箭头或键入)时,numericUpDown2也必须自动更改,同时保持正确的宽高比。
How can I do this? 我怎样才能做到这一点? I'm really lost.
我真的迷路了。
If the aspect ratio is simply defined like this: Width/Height, you should implement both the ValueChanged events of the two NumericUpDown controls: in the event for the numericUpDown1 (for width) you should set the new height value by dividing the numericUpDown1.Value by the aspect ratio; 如果像这样简单地定义宽高比:宽度/高度,则应同时实现两个NumericUpDown控件的ValueChanged事件:如果遇到numericUpDown1(用于宽度),则应通过除以numericUpDown1.Value来设置新的高度值。通过长宽比 in the other event you should multiply numericUpDown2.Value by the aspect ratio in order to get the new width.
在另一种情况下,您应该将numericUpDown2.Value乘以纵横比以获得新的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.