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 1 3743
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 needed to compile the client's code; this leads to a tight
coupling between the abstraction and its...
|
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.
|
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 of inheritance from base
classes.
If I am thinking from the point of view of some specific activity...
|
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 there in my library at all. I checked at MSN Libraryto find out all the System namespaces and I am...
|
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.
| |
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 a good time to introduce inheritance -- it's a good
fit for our data model, and it would greatly...
|
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?
|
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! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
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 to show a new form in the same
window?
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |