On May 28, 1:09 am, "Hamed" <ha...@raymehr.netwrote:
Hello
I have a UserControl sized to 100; 200
When I drop it in my form the initial size is 100;200 (as I prefer). Then I
decided to change the size of my UserControl to 200;200 but although I have
not set any value to the size of the dropped control in my form, recompiling
the project does not affect the new size of the user control in my form.
Surprisingly if I reset the Size property of my user control in the form,
the size changes to 150; 150! It seems some how, there is a DefaultValue for
Size property.
How can I solve my problem? I prefer when I resize my UserControl in form
designer, it affects all places it is used. another statement is I want my
default size affects from the main UserControl class.
Thanks in advance.
Hamed
Unless you add an attribute to your size property in your usercontrol,
it will not have a default size as far as the designer is concerned -
so the designer will add code that sets the size explicitly to the
size set when the control is created at design time.
To prevent this happening you need to tell the designer that this
control's size has a default.YOu should be able to do this using
[DefaultValue(typeof(System.Drawing.Size), "100, 200"] as an attribute
to the size property.
(I actrually just tried this, and it didn't work, as teh IDE seems to
still serialize the Size. As a work around, you can open the
Designer.cs file, and delete the line that sets your contorl's size -
from then on changing your usercontrol
s size will be reflected in the form where it is used. I'm not sure
why the DefaultValue isn't working 'properly' though- but I am sure
someone far cleverer than what I am will let us all know !)
Max