The inherited form will definitiely inherit all the functionality that is public, won't it?
Now ... event handlers for the controls mostly buttons are also inherited?
Another one...
I tried building the similar app as you demonstrated. I succeeded in inheriting the form.
I have two forms
- ParentForm
- InheritedForm
Both contain (The inherited will definitely..) One text box & one button
Initially I had coded parent display button to display text "You clicked display" in textbox. But after modifying I changed the code like follows
publicpartialclass ParentForm : Form
{
...
privatevoid btnDisplay_Click(object sender, EventArgs e)
{
InheritedForm form = new InheritedForm();
form.Show();
this.Hide();
}
}
wait wait ... isn't there any problem of constructor?? ya each time Inherited form is called the constructor of base class must also be called ..
But it is called only once.. then where is problem??
Is 'override' keyoword necessary? Sorry I was not aware of it as I come from C++ background.
I will try once again and then mail you. But where should I mail you Sir?
Plz help me find your address.
Still there is one question in my mind...
The event handler for button is 'private'. How can 'private' method or event handler be overridden? It should be separate for inherited class,shouldn't it?
You are creating an instance of InheritedForm in ParentForm. Now you do have an hen-and-egg problem, don't you? Both event handlers btnDisplay_Click are handled if you create an instance of InheritedForm and thus the text will be displayed in the hidden form, when the new instance pops up. Just remove the btnDisplay_Click handler in ParentForm and instantiate and show InheritedForm.
You must not create an instance of an inherited form in its base form (of course you can, but I have no idea why you would?), because by deriving from ParentForm you are instantiating InheritedForm. ParentForm I understand as a template for other forms, so create an instance of InheritedForm in your MainForm, which is now using ParentForm with its controls as its base and btnDisplay will work as expected (I think ).
Daniel Rühmer
Application engineer for Measurement Software
Wow .. now that was something that my dumb brain did not strike. Ya by doing that I am voilating OO principle of inheritance.
But, as a matter of factly it was just a test. Anyways. So it does have solution then. Fine.
When you select a control or component in the designer view, the properties window has a section named "Design". "GenerateMember" and "Modifiers" are two of the properties in that section. The latter can be used to change the visibility (private, protected, etc.) of the selected control or component, so you don't have to change the code by hand.
Excellent video, ya got my five. Hopefully this will be an inherited format
in the future.
Note to all : incorporate video with code for a richer learning experience.
All things being equal, tommorrow will never equal today