Designer Serialization Issues

  • Thread starter Thread starter Lucien Dol
  • Start date Start date
L

Lucien Dol

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.
 
Hi all,

Since nobody has yet responded to my cry for help, here's some more info
that might help assist me (or assist helping me?):

Closing the designer window in between complications and runs, does seem to
solve the problem over the ever-decreasing size, but I still have an initial
sizing problem.

To explain this further:
I initially set the size of the control (actually, it’s a few controls) to
fit the width of the form in the designer. I close and save the control. I
run the application. The width of the controls is as it should be. I exit
the application and re-open the form in the designer. The controls have
reverted back to a size almost half the width of the form!

I have checked the code to look at what I do with the size of the controls.
One (and only one) of the user controls on the form is adjusting its size
depending on certain conditions in the Resize event, which I presume will be
triggered when the size of the control or form on which the control is
“dropped” changes. This does not fit what I see anyway and does not explain
why the other controls don’t behave properly.

Perhaps a bit more detail is required. This is the “hierarchy” of form and
controls:

Form
|_ SplitContainer
|_ Panel1
|_ Panel2
|_SplitContainer
|_Panel1
|_TabControl
|_TabPage1
|_UserControl1
|_UserControl2
|_Standard Control

All the controls on the lowest level (inside TabPage1) suffer from the same
sizing problem.
Could it be it’s just getting too complicated for the designer because I
have multiple layers of controls and it involves two SplitContainers?

Just a thought…

Lucien.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top