为什么WinForms Control.Bottom和Control.Right是只读的? [英] Why are WinForms Control.Bottom and Control.Right read only?
问题描述
我知道可以通过操纵 Control.Top
和 Control.Height
来对齐控件的底部。同样是 Control.Right
。但是,为什么.NET决定不直接修改这些属性?自从我最近处理控制定位问题以来,它令人沮丧。
I know one can align bottom of a control by manipulating Control.Top
and Control.Height
. And similarly Control.Right
. But why is that .NET decided to not let these properties be modified directly? Its frustrating since last few fays I have been dealing with control positioning.
推荐答案
简短答案:
我相信他们已经将底部
和右
读为-仅仅是,不是因为在技术上是必要的,而是作为记录这些这些属性的方法,这些属性会在 Top
/ <$时重新计算c $ c>高度或左
/ 宽度
。
Short answer:
I believe they have made Bottom
and Right
read-only, not because it is technically necessary, but as a way of documenting that it is these properties that get re-computed when Top
/Height
or Left
/Width
are modified.
有两个属性集:一个用于绝对坐标(顶部
,底部
,左
,右
)和一个尺寸( Height
, Width
)。它们之间的关系通过以下两个不变量定义:
There are two property sets: One for absolute coordinates (Top
, Bottom
, Left
, Right
), and one for dimension (Height
, Width
). The relationship between these is defined through the following two invariants:
-
Width == Right-Left
-
高度==底部-顶部
Width == Right - Left
Height == Bottom - Top
现在,例如,如果Microsoft决定 Top
属性应为可写属性,则他们需要做出进一步的设计决策:是否会更改顶部
...
Now if, for example, Microsoft decides that the Top
property should be writable, they need to make one further design decision: Will a change in Top
...
- 影响
高度
并保留底部
,或 - 保留
高度
并影响底部
?
- affect
Height
and preserveBottom
, or - preserve
Height
and affectBottom
?
除非他们引入了某种允许的其他锚属性用户选择,Microsoft 必须决定这些后果之一,以保证上面的不变式(2)。
Unless they introduce a further "anchor" property of some sort that allows the user to choose, Microsoft must decide on one of these consequences to guarantee invariant (2) above.
显然,他们决定了后者两种选择。接下来,Microsoft将需要记录他们的决定。他们可以在其MSDN参考页上提及调整 Top
的后果...事实证明,他们只是这样做了:
Obviously they decided on the latter of the two alternatives. Next, Microsoft would have needed to document their decision. They could either mention the consequences of adjusting Top
on their MSDN reference pages... and it turns out they did just that:
对
Height
和Top
属性值的更改导致底部
要更改的控件的属性值。— <$$的MSDN参考页面的备注部分c $ c> Control.Top 属性
Changes made to the
Height
andTop
property values cause theBottom
property value of the control to change. — Remarks section of the MSDN reference page for theControl.Top
property
...或者他们可以声明 Bottom
属性为只读,向我们建议程序员该属性取决于其他两个属性( Top
和 Height
)...他们也 已完成:
... or they could declare the Bottom
property as read-only, suggesting to us programmers that this property depends on the other two (Top
and Height
)... which they have also done:
底部
属性是只读属性。您可以通过更改Top
或Height
属性[...] — <$$的MSDN参考页面的备注部分c $ c> Control.Bottom 属性
The
Bottom
property is a read-only property. You can manipulate this property value by changing the value of theTop
orHeight
properties [...] — Remarks section of the MSDN reference page for theControl.Bottom
property
所以他们已经记录了(任意)设计决策既可以用英语进行,也可以通过代码进行。
So they have documented their (arbitrary) design decision both in English, and additionally through code.
这篇关于为什么WinForms Control.Bottom和Control.Right是只读的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!