473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance of controls and forms ...

Hi all

It is maybe a stupid question, but I have some
trouble with Inheritance.

For example:
I create a new class with one form.
On this form I place on the bottom a Panel
and on this Panel on the right side a button.
On both controls I set Anchor (bottom, right).

Then I create a new Windows Form application.
I add a reference to my base class and add new form.
I change to the code view of the new form and I change from
"public partial class Form2 : Form"
to
"public partial class Form2 : MyBaseClassForm "
it is changeing the form as expected.

Then the problem:
I only change the size (making it bigger) of the new form,
save and close it.
When I now open the new form again, the panel and the button
are somewhere on the form, not on the buttom as expected.

What am I doing wrong ??
Thanks for any comments.

Best regards
Frank
Jul 22 '08 #1
3 1786
On Tue, 22 Jul 2008 08:36:01 -0700, Frank Uray
<Fr*******@disc ussions.microso ft.comwrote:
[...]
Then the problem:
I only change the size (making it bigger) of the new form,
save and close it.
When I now open the new form again, the panel and the button
are somewhere on the form, not on the buttom as expected.
I assume "buttom" is supposed to be "bottom", and not "button"?

As for what you're doing "wrong", I'm not sure there's a good answer to
that. I understand why you would expect the Panel and Button to remain
where they were. But the Designer is only going to edit the Designer.cs
file for the Form sub-class currently being designed. Your Panel and
Button locations are actually declared in your base class's
InitializeCompo nent() method, and dragging the sub-class's size in the
Designer won't affect that.

One wouldn't think that this would matter, but because of the way the
Designer-generated code lays things out, it does. In particular, it
suspends layout during all of the initialization of the form itself, and
when layout is suspended, anchored items don't respond to changes in the
form size.

So, your form goes through two size changes: once in the base class, and
then later in the sub-class. During both of those size changes, layout is
suspended, and so the anchored controls just remain where they are, even
when the sub-class size changes after the base class controls have been
positioned and anchored.

I don't personally have a great solution to that issue. It's a difficult
issue for Designer to address, One might think that it's a bug in the
Designer to allow the anchored controls to move when you resize the
sub-class form. After all, since the actual run-time sizing will happen
with layout suspended, it seems like layout also ought to be suspended
during Designer editing. It wouldn't do what you want, but at least the
Designer would more correctly reflect what's going on.

But having layout suspended in the _same_ class where the controls are
declared isn't a problem, and you _do_ want the controls' position to be
updated during Designer editing, because the Designer can manage those
just fine (after all, they're in the class being designer, so the Designer
has write access to them). Just detecting the sub-class case and
disabling layout during dragging wouldn't even be sufficient, because of
the same need to move the controls that are declared within the form class
the size of which is actually be modified.

An alternative approach the Designer might take would be to explicitly
search for anchored child controls in base classes and add code to the
sub-class's InitializeCompo nent() method to handle them, but that starts
to get pretty messy.

In other words, I feel your pain, and I agree that it's frustrating for
the Designer to not give true "WYSIWYG" results. But I'm also not sure
that there's an obvious, simple way to fix the Designer so that it gives
the results you want. For better or worse (to some extent, mostly worse
:) ), dealing with design of sub-classes of designed forms is problematic,
for a variety of reasons. This just happens to be one of them.

Possible workaround I see include:

-- making the sub-class form non-resizable (not applicable in all
situations, of course).
-- explicitly managing anchoring behavior yourself (in the base class
constructor, examine and store the current offsets related to anchoring
for all the current child controls that are anchored, and then reapply
those offsets later, such as in the OnLoad() method).

Hope that helps.

Pete
Jul 22 '08 #2
So a concise version of the previous post is that the layout is suspended
while the form is sized so the panel and button dont track the form size
changed and are positioned at the same top and left as they are in the base
for. The only way to get round this is with docking. Docking the panel bottom
and the button right would make the work.
You can mess around witht the maximum size to keep the button from looking
strange and hugging the corner so tightly or use a FlowLayoutPanel docked
bottom with layout right to left.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Peter Duniho" wrote:
On Tue, 22 Jul 2008 08:36:01 -0700, Frank Uray
<Fr*******@disc ussions.microso ft.comwrote:
[...]
Then the problem:
I only change the size (making it bigger) of the new form,
save and close it.
When I now open the new form again, the panel and the button
are somewhere on the form, not on the buttom as expected.

I assume "buttom" is supposed to be "bottom", and not "button"?

As for what you're doing "wrong", I'm not sure there's a good answer to
that. I understand why you would expect the Panel and Button to remain
where they were. But the Designer is only going to edit the Designer.cs
file for the Form sub-class currently being designed. Your Panel and
Button locations are actually declared in your base class's
InitializeCompo nent() method, and dragging the sub-class's size in the
Designer won't affect that.

One wouldn't think that this would matter, but because of the way the
Designer-generated code lays things out, it does. In particular, it
suspends layout during all of the initialization of the form itself, and
when layout is suspended, anchored items don't respond to changes in the
form size.

So, your form goes through two size changes: once in the base class, and
then later in the sub-class. During both of those size changes, layout is
suspended, and so the anchored controls just remain where they are, even
when the sub-class size changes after the base class controls have been
positioned and anchored.

I don't personally have a great solution to that issue. It's a difficult
issue for Designer to address, One might think that it's a bug in the
Designer to allow the anchored controls to move when you resize the
sub-class form. After all, since the actual run-time sizing will happen
with layout suspended, it seems like layout also ought to be suspended
during Designer editing. It wouldn't do what you want, but at least the
Designer would more correctly reflect what's going on.

But having layout suspended in the _same_ class where the controls are
declared isn't a problem, and you _do_ want the controls' position to be
updated during Designer editing, because the Designer can manage those
just fine (after all, they're in the class being designer, so the Designer
has write access to them). Just detecting the sub-class case and
disabling layout during dragging wouldn't even be sufficient, because of
the same need to move the controls that are declared within the form class
the size of which is actually be modified.

An alternative approach the Designer might take would be to explicitly
search for anchored child controls in base classes and add code to the
sub-class's InitializeCompo nent() method to handle them, but that starts
to get pretty messy.

In other words, I feel your pain, and I agree that it's frustrating for
the Designer to not give true "WYSIWYG" results. But I'm also not sure
that there's an obvious, simple way to fix the Designer so that it gives
the results you want. For better or worse (to some extent, mostly worse
:) ), dealing with design of sub-classes of designed forms is problematic,
for a variety of reasons. This just happens to be one of them.

Possible workaround I see include:

-- making the sub-class form non-resizable (not applicable in all
situations, of course).
-- explicitly managing anchoring behavior yourself (in the base class
constructor, examine and store the current offsets related to anchoring
for all the current child controls that are anchored, and then reapply
those offsets later, such as in the OnLoad() method).

Hope that helps.

Pete
Jul 22 '08 #3
Hi Pete

Thanks a lot for your loong comments.

As the other comment was writing, I tried
to do it with docking, and this is better.
It has to be a combination of docking
and anchoring.
In my example, I dock the panel to the
bottom and anchor the button to bottom/right,
this seams to work.

Thanks and best regards
Frank Uray
"Peter Duniho" wrote:
On Tue, 22 Jul 2008 08:36:01 -0700, Frank Uray
<Fr*******@disc ussions.microso ft.comwrote:
[...]
Then the problem:
I only change the size (making it bigger) of the new form,
save and close it.
When I now open the new form again, the panel and the button
are somewhere on the form, not on the buttom as expected.

I assume "buttom" is supposed to be "bottom", and not "button"?

As for what you're doing "wrong", I'm not sure there's a good answer to
that. I understand why you would expect the Panel and Button to remain
where they were. But the Designer is only going to edit the Designer.cs
file for the Form sub-class currently being designed. Your Panel and
Button locations are actually declared in your base class's
InitializeCompo nent() method, and dragging the sub-class's size in the
Designer won't affect that.

One wouldn't think that this would matter, but because of the way the
Designer-generated code lays things out, it does. In particular, it
suspends layout during all of the initialization of the form itself, and
when layout is suspended, anchored items don't respond to changes in the
form size.

So, your form goes through two size changes: once in the base class, and
then later in the sub-class. During both of those size changes, layout is
suspended, and so the anchored controls just remain where they are, even
when the sub-class size changes after the base class controls have been
positioned and anchored.

I don't personally have a great solution to that issue. It's a difficult
issue for Designer to address, One might think that it's a bug in the
Designer to allow the anchored controls to move when you resize the
sub-class form. After all, since the actual run-time sizing will happen
with layout suspended, it seems like layout also ought to be suspended
during Designer editing. It wouldn't do what you want, but at least the
Designer would more correctly reflect what's going on.

But having layout suspended in the _same_ class where the controls are
declared isn't a problem, and you _do_ want the controls' position to be
updated during Designer editing, because the Designer can manage those
just fine (after all, they're in the class being designer, so the Designer
has write access to them). Just detecting the sub-class case and
disabling layout during dragging wouldn't even be sufficient, because of
the same need to move the controls that are declared within the form class
the size of which is actually be modified.

An alternative approach the Designer might take would be to explicitly
search for anchored child controls in base classes and add code to the
sub-class's InitializeCompo nent() method to handle them, but that starts
to get pretty messy.

In other words, I feel your pain, and I agree that it's frustrating for
the Designer to not give true "WYSIWYG" results. But I'm also not sure
that there's an obvious, simple way to fix the Designer so that it gives
the results you want. For better or worse (to some extent, mostly worse
:) ), dealing with design of sub-classes of designed forms is problematic,
for a variety of reasons. This just happens to be one of them.

Possible workaround I see include:

-- making the sub-class form non-resizable (not applicable in all
situations, of course).
-- explicitly managing anchoring behavior yourself (in the base class
constructor, examine and store the current offsets related to anchoring
for all the current child controls that are anchored, and then reapply
those offsets later, such as in the OnLoad() method).

Hope that helps.

Pete
Jul 23 '08 #4

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

Similar topics

1
3743
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
2
2191
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
1
8001
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work under 2002) Create a form and add two buttons (bottom right) and a panel (fill the top of the form) Anchor the buttons to the bottom right and anchor the panel to top bottom left and right. set all three controls access level to protected
1
1056
by: Wayne | last post by:
I have two forms, frmBase and frmInherited. frmInherited inherits from frmBase. On frmBase I have 8 controls, these 8 controls show up on frmInherited but not always in the same position as they are on frmBase. I have the following questions: 1) how do I fix this? 2) how do I prevent the forms on frmInherited from being moved, but yet still allow for one of them to have it's caption changed and events assigned to it?
4
2148
by: Jason Huang | last post by:
Hi, In my ASP.Net 1.1, C#, I have two windows forms, one is frmContactPerson, another is frmContactAddress. These two forms has many same Controls, except in one GroupBox they have different TextBoxes showing different data from datatable ContactPerson and ContactAddress respectively. Now come my question: How am I gonna apply the "Inheritance" concept in that situation? Any help will be appreciated.
6
2089
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself so, cannot be called a WebForm itself, the child pages will implement forms). I created a Master.aspx page and removed all HTML from it, added some code to the .aspx.vb file to add controls to my page. Then I created a Child.aspx and changed the...
15
330
by: scorpion53061 | last post by:
I am just now really starting to get into inheritance - controls, datasets, views all that stuff and I am seeing the enormous savings in performance and even watching the exe file size go down which is making me very happy. I am frustrated a bit though it seems to be costing me more time in that I am kind of not seeing the entire picture in the development environment. I was wondering how you more experienced folks handle this ......I...
20
2588
by: Michael Maes | last post by:
Hello, I have a BaseForm with (eg) one Timer in the Components'collection & one Button in the Controls'Collection Also there are three Subs: Load, ScanControls & ScanComponents. The BaseForm is only used to be inherited from (and inherits from System.Windows.Forms.Form). Private Sub BaseForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ScanControls() ScanComponents()
2
2184
by: Ray Cassick \(Home\) | last post by:
Since I got such good feedback from the Xml comments question I will ask this of the group as well. Is VS.NET 2005 handling the visual inheritance problems centered around controls and forms that are decorated with MustInherit any better than 2003 did? I am getting really tired of having to do the good old '#If DEBUG Then' workaround just to get by this.
0
1174
by: =?Utf-8?B?SGVsZ2U=?= | last post by:
Hi! I have run into a problem with visual inheritance using the VS2005 designer for Windows Forms. My goal is to put business logic and common rules for our controls into its own layer (base classes) so that future changes in these controls are managed by just modifying this custom layer, and not all the controls of a particular type.
0
8469
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8463
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
8128
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,...
1
5997
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
5471
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
3953
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
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
1
1574
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.