The reason that the Form.Size property is not available in the parameter binding interface is because this property is marked with DesignerSerializationVisibility.Hidden . This means that the developer does not know how to serialize it, not to mention creating a data binding for it. Instead, the Form.ClientSize property is serialized.
If you try to get smarter by linking Location and ClientSize , you will see another problem. When you try to resize your shape to the left or top, you will see strange behavior. This, apparently, is related to how two-way data binding works in the context of sets of properties that mutually influence each other. Both Location and ClientSize eventually call the common SetBoundsCore () method.
In addition, data binding to properties such as Location and Size is simply ineffective. Every time a user moves or resizes a form, Windows sends hundreds of messages to the form, forcing the data binding logic to do more processing when all you really need is to keep the last position and size until the form is closed.
This is a very simplified version of what I am doing:
private void MyForm_FormClosing(object sender, FormClosingEventArgs e) { Properties.Settings.Default.MyState = this.WindowState; if (this.WindowState == FormWindowState.Normal) { Properties.Settings.Default.MySize = this.Size; Properties.Settings.Default.MyLoc = this.Location; } else { Properties.Settings.Default.MySize = this.RestoreBounds.Size; Properties.Settings.Default.MyLoc = this.RestoreBounds.Location; } Properties.Settings.Default.Save(); } private void MyForm_Load(object sender, EventArgs e) { this.Size = Properties.Settings.Default.MySize; this.Location = Properties.Settings.Default.MyLoc; this.WindowState = Properties.Settings.Default.MyState; }
Why is this a very simplified version? Because doing it right is a lot harder than it looks :-)
RoadWarrior Nov 04 '08 at 2:59 2008-11-04 02:59
source share