Hi all,
Can someone help me with this, please?
I've got a user control that (amongst other controls) contains a textbox.
The textbox has its Anchor property set to "Left, Top, Right", meaning that
it will stretch automatically when the control is resized on a form or other
user control. When in design mode I look at the control by itself (rather
than dropped on a form) the control has a certain size (let's call this
SizeA).
This user control is dropped on another user control that is dropped onto a
form that is slightly wider. I set all the Anchor and Dock properties so
that the controls neatly fill the forms.
When I run the application all works fine and the controls sizes as it
should when required.
On closing the application the user control (when looking at the form it's
on) has shrunk and now has a different size (SizeB), while when I look at
the control in its own designer window it still has the original size.
If I run the application again (without correcting the control's size) the
control now starts with the smaller size (i.e. no longer fills the width of
the form) even though it will still stretch when I resize the form.
Exit the application again and - voila! - the control is even smaller
(SizeC)!
When I look at the Control.Designer.cs file in between runs I can see that
the Windows forms generator changes the Size property between each run of
the application.
Why does this happen and how can I fix it? Does it have something to do with
the designer serialization? If so, how do I add a
DesignerSerializationAttribute to the textbox or the control itself in such
a way that it retains its correct size? And can I do this interactively
somehow or do I need to overwrite some properties in code? Or is there
another way?
Any help is appreciated.
Lucien Dol.