K
KK
** 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.
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.EventArgs e)
and then edit the close button event in the
child form to;
protected override void btnClose_Click(object sender, System.EventArgs e)
And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).
//this.btnClose.Click += new System.EventHandler(this.btnNew_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?
Regards
KK
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.EventArgs e)
and then edit the close button event in the
child form to;
protected override void btnClose_Click(object sender, System.EventArgs e)
And then, in the child forms' event registration for
CLOSE button should be removed/commented(the line below).
//this.btnClose.Click += new System.EventHandler(this.btnNew_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?
Regards
KK