473,836 Members | 1,519 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 8342
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******** ******@TK2MSFTN GP10.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 ShouldSerialize Size() 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.lvwBusines sObjects.MultiS elect = 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 ShouldSerialize Size() in your parent Form:

private bool ShouldSerialize Size()
{
return this.Size.Width == 1000 && this.Size.Heigh t == 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 ShouldSerialize Size() 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*******@cana da.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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 ShouldSerialize Size()
{
return this.Size.Width == 1000 && this.Size.Heigh t == 500;
}

Oh crap. That's backward. I meant:

private bool ShouldSerialize Size()
{
return this.Size.Width != 1000 || this.Size.Heigh t != 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*******@cana da.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
This probably involves monkeying around with the DefaultValue()
attribute on the Size property of your inherited form, or implementing
a ShouldSerialize Size() 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.lvwBusines sObjects.MultiS elect = 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 ShouldSerialize Size() in your parent Form:

private bool ShouldSerialize Size()
{
return this.Size.Width == 1000 && this.Size.Heigh t == 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 ShouldSerialize Size() 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
1391
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 inside an outer form. this is obviously a relevant issue with ASPX as webcontrols need to reside inside a server side form. i found a work around which will allow u to nest multiple forms. straight after your server side form add a "dummy" form...
11
1906
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 therefore the only way to prevent users from moving forms is to have forms with no borders, is there a way in Access 97 to mimic the Moveable Property? Patrick
0
1312
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 properly with standard MDI forms. The constructor of the class is something like SemiMDI(System.Windows.Forms.Form client,System.Windows.Forms.Panel parentArea)
7
1384
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 working for my child forms. Herfried K. Wagner directed me to a code sample which he wrote as a work around for this problem. Very interesting code. You're obviously light years ahead of me in programing skills. Some day in the near future I plan...
0
4497
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. So, I tricked my Transparent Non-MDI Child form into my MDI-Container form via SetParent API as seen here in my VB.NET sample ( http://wuhenry.beigetower.org/position.zip ). I thought my problems are over, but apprently, even though I...
2
2715
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. 3. To the right of that splitter would be a second tree we call a palette. 4. To the right of the palette would be another splitter. 5. To the right of that splitter would be our "content area". We are trying to find a way to allow this...
8
2025
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 doesn't separate itself from the child form, meaning you can't move it around like if the form was "restored" but it doesn't take up all the space available. I do not have the maximum or minimum size set in the properties, but I do have the...
1
2331
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 load it (at run time) as the form background. then, on top of it I place the fields. Seems to work well. Now I am trying to allow use of the resize utility to allow the form to
1
5781
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 the user changes the computer settings. I'm not interested in the event that fires, what I need is an approach to setting the font that is not hard-coded to a specific size such as 10 or 12. I don't see that available in .NET controls, am I missing...
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10600
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10257
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7794
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4459
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 we have to send another system
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.