473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How come my forms wont resize...

I have a form that I inherited from System.Windows.Forms. I use that form
everywhere in my system. I went back to my base class form and changed the
size, expecting all of my children forms to inherit the base class forms
size.

This is not what happened. All of my children forms thought the size
property was overridden. They stayed the old size.

How can I get my children forms to respect the parents size property? I am
assuming this is not specific to the size property. How can I get my
children forms to repsect any parent form property without visiting each
form?
Nov 17 '05 #1
6 8300
Hi,

No really, you see by default the form constructor call Initialize() that is
where all the controls and form properties are assigned ( this is the
designer's gneraet code) s. This method is not virtual, so what happens is
that your derived form call first its parent ( your template form) the
latter in its constructor initialize it self, then the derived constructor
runs and as part of this a call to the derived Initialized method is
performed, hence overwritting the parent's value.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ty Salistean" <ts******@yahoo.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
I have a form that I inherited from System.Windows.Forms. I use that form
everywhere in my system. I went back to my base class form and changed
the
size, expecting all of my children forms to inherit the base class forms
size.

This is not what happened. All of my children forms thought the size
property was overridden. They stayed the old size.

How can I get my children forms to respect the parents size property? I
am
assuming this is not specific to the size property. How can I get my
children forms to repsect any parent form property without visiting each
form?

Nov 17 '05 #2
This probably involves monkeying around with the DefaultValue()
attribute on the Size property of your inherited form, or implementing
a ShouldSerializeSize() method. Here is what is going on now:

Each property of every Control can define a DefaultValue attribute for
that property. This attribute tells Visual Studio Designer that if the
value of that property is equal to the given default value, don't
bother serializing the property in the "Windows Designer Generated
Code" section of your class. For example, the default value for the
MultiSelect property of the ListView control is true, so if you leave
it at true, Visual Studio Designer won't insert any code to initialize
that property. Only if you change it to false will you see:

this.lvwBusinessObjects.MultiSelect = false;

Since your redefined Form doesn't define a new default value for the
form size, Visual Studio Designer will _always_ serialize the size of
the form or of any child forms, because the form's size is different
from the default established on the base Form class (if there even is
one). So, in the code marked "Windows Designer Created Code" there will
always be a line like this:

this.Size = new Size(400, 500);

because Visual Studio Designer sees that the form size is not equal to
the default of 300, 300, and so it thinks that it has to insert code to
initialize the size. (Or maybe there is no default defined for Form...
I don't know.)

Anyway, you have to tell Visual Studio to not bother serializing the
form size if it is equal to that of the parent form. Unfortunately,
there's no way to do this other than hard-coding the form size into the
parent Form's class. I would try the following to see if it works.
Define a new method called ShouldSerializeSize() in your parent Form:

private bool ShouldSerializeSize()
{
return this.Size.Width == 1000 && this.Size.Height == 500;
}

for example. This should cause Visual Studio Designer to check the
child form's size to see if it is 1000 x 500. If it is, the Designer
won't insert any code to set the size of the child form.

The only drawback is that whenever you change the size of your parent
form, you have to remember to fix the ShouldSerializeSize() method.
(And no, you can't just compare this.Size.Width with base.Size.Width or
something like that. If you think about it you'll realize why that
wouldn't work.)

I'm still learning about exactly how the Designer works with defaults
and the class hierarchy, so don't be surprised if this doesn't work at
the outset. Let us know what happens and we can try other solutions if
this doesn't do it.

Nov 17 '05 #3
> How can I get my children forms to respect the parents size property?

You realize, of course, that getting children to respect their parents'
_anything_ is a lifelong challenge? ;-)

Nov 17 '05 #4
i feel that pain ;-)

thanks for the explaination...

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
How can I get my children forms to respect the parents size property?


You realize, of course, that getting children to respect their parents'
_anything_ is a lifelong challenge? ;-)

Nov 17 '05 #5
private bool ShouldSerializeSize()
{
return this.Size.Width == 1000 && this.Size.Height == 500;
}

Oh crap. That's backward. I meant:

private bool ShouldSerializeSize()
{
return this.Size.Width != 1000 || this.Size.Height != 500;
}

Nov 17 '05 #6
Here is what I found out.

If you take the scenario that I posed in my first post AND you do not have
any controls on your child form, then the form behaves as expected. I set
the width property back 100 pixles on the parent and my child responds
appropriately.

The second that I put controls on my child form, the child form adds an
entry to the Initialize Components
this.ClientSize = new System.Drawing.Size(1012, 273);

Even if I right click on the property on the child form and click "Reset to
Default", this line of code is not removed. It simply gets set to the
parents size.

I guess (after thinking about this) this is not a bad thing. If I make the
parent form really tiny, then I run the risk of hiding controls on the child
forms where that propery has not been overridden.

It is a bad thing cuz if you want to develop an app at 800x600 knowing that
you will move to 1024x768, you have to go to all of your child forms and
revisit this setting. That may not be a bad thing cuz your controls would
need to get moved or resized to accomodate the new design area.

I think if you weigh the factors in here, I think I would actually agree
that this is a good behavior. It looks like this will be one of the only
properties affected, given what I am seeing in the Initialize Components.

I tested that with the Minimizebox property on the parent form. The child
form did get the change appropriately.

Thanks for the post - but I think I am going to leave this one alone. It
could keep me from doing stupid things...

Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This probably involves monkeying around with the DefaultValue()
attribute on the Size property of your inherited form, or implementing
a ShouldSerializeSize() method. Here is what is going on now:

Each property of every Control can define a DefaultValue attribute for
that property. This attribute tells Visual Studio Designer that if the
value of that property is equal to the given default value, don't
bother serializing the property in the "Windows Designer Generated
Code" section of your class. For example, the default value for the
MultiSelect property of the ListView control is true, so if you leave
it at true, Visual Studio Designer won't insert any code to initialize
that property. Only if you change it to false will you see:

this.lvwBusinessObjects.MultiSelect = false;

Since your redefined Form doesn't define a new default value for the
form size, Visual Studio Designer will _always_ serialize the size of
the form or of any child forms, because the form's size is different
from the default established on the base Form class (if there even is
one). So, in the code marked "Windows Designer Created Code" there will
always be a line like this:

this.Size = new Size(400, 500);

because Visual Studio Designer sees that the form size is not equal to
the default of 300, 300, and so it thinks that it has to insert code to
initialize the size. (Or maybe there is no default defined for Form...
I don't know.)

Anyway, you have to tell Visual Studio to not bother serializing the
form size if it is equal to that of the parent form. Unfortunately,
there's no way to do this other than hard-coding the form size into the
parent Form's class. I would try the following to see if it works.
Define a new method called ShouldSerializeSize() in your parent Form:

private bool ShouldSerializeSize()
{
return this.Size.Width == 1000 && this.Size.Height == 500;
}

for example. This should cause Visual Studio Designer to check the
child form's size to see if it is 1000 x 500. If it is, the Designer
won't insert any code to set the size of the child form.

The only drawback is that whenever you change the size of your parent
form, you have to remember to fix the ShouldSerializeSize() method.
(And no, you can't just compare this.Size.Width with base.Size.Width or
something like that. If you think about it you'll realize why that
wouldn't work.)

I'm still learning about exactly how the Designer works with defaults
and the class hierarchy, so don't be surprised if this doesn't work at
the outset. Let us know what happens and we can try other solutions if
this doesn't do it.

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1361
by: Jamie | last post by:
Just thought i'd post this tip for developers who are having problems submitting HTML forms which reside inside a parent ASPX web form. basically, HTML forms wont submit correctly if they're...
11
1873
by: Patrick Fisher | last post by:
Later versions of Access have form property called Moveable which, if set, prevents users from moving forms yet still allows the form to retain a border. Access 97 does not have this property...
0
1295
by: Bisbal | last post by:
Hi All, I have created a class that simulates a MDI form by putting the 'child' inside a panel located in the 'parent' form. I had to do this because we use a custom UI that doesn't work...
7
1364
by: What-a-Tool | last post by:
I have an mdichild form whose minimum size I want to limit (can't be dragged below a certain size) Even though I am running .NET 1.1 where the minimum size property supposedly works, it's not...
0
4460
by: Henry Wu | last post by:
Hi, I am aware that TransparencyKey only works with top-level forms or Non-MDI Child Forms, if one tries to set the opacity or transparencykey property to a MDI-Child form, it will have no effect....
2
2689
by: Gary Shell | last post by:
We are playing around with using the splitter on a form and want to do the following: 1. On the left side of the form will be a tree view. 2. To the right of that tree view would be a splitter....
8
2001
by: Tony K | last post by:
How do you maximize a child form when you show the child form. My resolution on my screen is 1440 x 900. My parent form maximizes just fine, but when I show a child form it doesn't maximize. It...
1
2314
by: Bob Alston | last post by:
Anyone use the AHRESIZE utility to resize a form dynamically who is also using background images? I have an app that creates electronic versions of manual forms. I digitize the manual form and...
1
5754
by: =?Utf-8?B?dmFwb3I=?= | last post by:
I'm interested in getting a Windows forms font to resize similar to what happens with the Windows toolbars when the end-user changes the system font. With the Windows toolbar, the font 'grows' as...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.