472,993 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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 1760
On Tue, 22 Jul 2008 08:36:01 -0700, Frank Uray
<Fr*******@discussions.microsoft.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
InitializeComponent() 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 InitializeComponent() 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*******@discussions.microsoft.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
InitializeComponent() 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 InitializeComponent() 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*******@discussions.microsoft.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
InitializeComponent() 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 InitializeComponent() 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
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...
2
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...
1
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...
1
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...
4
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...
6
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...
15
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...
20
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...
2
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...
0
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.