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.
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.
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 Height == Bottom - TopNow 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...
Height and preserve Bottom, orHeight and affect Bottom?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.
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:
Changes made to the
HeightandTopproperty values cause theBottomproperty value of the control to change. — Remarks section of the MSDN reference page for theControl.Topproperty
... 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:
The
Bottomproperty is a read-only property. You can manipulate this property value by changing the value of theToporHeightproperties [...] — Remarks section of the MSDN reference page for theControl.Bottomproperty
So they have documented their (arbitrary) design decision both in English, and additionally through code.
To quote Eric Lippert: " You keep on asking "why?" questions, which I find difficult to answer because your question is secretly a "why not?" question. That is, the question you really mean to ask is "I have a notion of how the [feature] obviously ought to have been designed; why is it not like that?" "
The answer to "why not?" question is probably between:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With