473,545 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Forms Inheritance, Incomplete?

KK
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.

Lets say for example, I have 2 forms and both
forms have buttons as (New, Edit, Save, Close)

Both the forms before showing, should do a
security check(say in forms load event)

In the old vb scenerio, we would create 2 similar
forms seperately and do code cut and paste
for each form which have the similar functions.

But here, with forms inheritance this should
be automaticaly done. But what happense when
u inherit a form at the moment is, it only
sets the controls MODIFIER poperty to
say Protected, Proteted Internal etc..

But If I want to override the parent forms
functionality , say overriding CLOSE buttons
click method, I have to manually edit
the parents click event as;

protected virtual void btnClose_Click( object sender, System.EventArg s e)

and then edit the close button event in the
child form to;

protected override void btnClose_Click( object sender, System.EventArg s e)

And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).

//this.btnClose.C lick += new System.EventHan dler(this.btnNe w_Click);

Otherwise, when the child instance get created
it will register 2 events(cause it goes up the
inheritance hierachy and creates parent form instance
first and then come back to child form)
so if u click CLOSE button once,
it will call the close method twise!!!!!

My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work.

I want to know what you guys think. May be
I have taken the whole thing from the wrong
end.

May be forms inheritance is there ONLY to get the
UI duplicated? is it?

Rgds
KK
Jul 19 '05 #1
1 3733
KK,
Why go though all that work?

I would use the Template Pattern to introduce a virtual OnClose method to
the base form, that the derived form could override and alter the flow.

The base form's btnClose_Click event handler would call this OnClose method.
The base form's OnClose would have the default behavior (none?) for OnClose,
while the derived form's OnClose would do what was needed.

In Release builds I would consider making OnClose abstract, while in Debug
builds I would make it virtual, as the Forms Designer does not like abstract
base forms. In Debug builds, if the method is meant to be overridden, I
normally make the base.OnClose method simply throw a
NotImplementedE xception. This way I find out real quick if I forgot to
override the method ;-)
My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work. My question would be, why automatic this when the Template Pattern seems to
be a cleaner more OOP solution? :-)

Hope this helps
Jay

"KK" <kk@kk.com> wrote in message
news:el******** *****@tk2msftng p13.phx.gbl... 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.

Lets say for example, I have 2 forms and both
forms have buttons as (New, Edit, Save, Close)

Both the forms before showing, should do a
security check(say in forms load event)

In the old vb scenerio, we would create 2 similar
forms seperately and do code cut and paste
for each form which have the similar functions.

But here, with forms inheritance this should
be automaticaly done. But what happense when
u inherit a form at the moment is, it only
sets the controls MODIFIER poperty to
say Protected, Proteted Internal etc..

But If I want to override the parent forms
functionality , say overriding CLOSE buttons
click method, I have to manually edit
the parents click event as;

protected virtual void btnClose_Click( object sender, System.EventArg s e)

and then edit the close button event in the
child form to;

protected override void btnClose_Click( object sender, System.EventArg s e)

And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).

//this.btnClose.C lick += new System.EventHan dler(this.btnNe w_Click);

Otherwise, when the child instance get created
it will register 2 events(cause it goes up the
inheritance hierachy and creates parent form instance
first and then come back to child form)
so if u click CLOSE button once,
it will call the close method twise!!!!!

My question is why they didn't automate this couple
of steps ? If a forms controls have been set to
Protected / Protected Internal, they could have
generate the code so that it will really
work.

I want to know what you guys think. May be
I have taken the whole thing from the wrong
end.

May be forms inheritance is there ONLY to get the
UI duplicated? is it?

Rgds
KK

Jul 19 '05 #2

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

Similar topics

1
379
by: Tony Johansson | last post by:
Hello! What does this mean. "The use of inheritance to provide various implementations of a single abstraction tightly binds these implementations to the abstarction. Therfore it, is difficult to update the client's code and reuse the abstraction, In C++, the complete class definition, including the private and protected sections, is...
1
352
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.
7
12862
by: Hazz | last post by:
Are there any good references/articles/books which provide clarity toward my insecurity still on deciding how to model a complex system? I still feel uncomfortable with my understanding, even though I have worked with these systems on when to decide to use interfaces (and how they should be developed) as opposed to or complemented by the use...
1
5137
by: Rob Deacon via .NET 247 | last post by:
I am just getting into this .NET stuff. Looks really handy. I wastrying to run some standard tests, like throwing up aMessageBox.Show("Code Hit Here - ln 124"); Just to make sure Iwas building things right. I realize I needed to use a few things from the library to makethis work, one of the big ones being System.Windows.Forms, butit wasn't...
4
2144
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...
5
2858
by: jao | last post by:
My company's product uses Postgres 7.4.3. Postgres is working well for us, and we've worked through many performance issues by tweaking the schema, indexes, and posgresql.conf settings. Inheritance would be useful for our application, but we did not use this feature initially. We're about to revise part of our application, and this would be...
1
1388
by: jc | last post by:
Hello. I'm doing some prep work before taking the vb.net brainbench. I noticed one of the topics is : Consuming resources - Windows Native Calls Where can I get more info on this? What exactly is a Windows Native call? Controls that talk to the OS?
12
11031
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed!...
9
1791
by: Scott Stark | last post by:
Hello, I'm *just* delving into Windows forms-based programming without the benefit of any books, etc. I have a background in light ASP.NET work, so forgive me if this is a really basic question related to Windows GUI. I've created a "Form1.vb" file in my project, added a menustrip, etc. When a user clicks on a menu item, how do I get it...
0
7502
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7434
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...
0
7692
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. ...
0
7946
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...
0
7791
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...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5078
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...
0
3491
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...
1
1921
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

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.