C# Windows Form Inheritance Quesiton

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

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.

Jason
 
What do you want to do? Your post does not really make that clear. Do you
want to create one form that inherits from both forms? Do you want to reuse
the current controls?
 
Thanks Peter.
I'm trying to apply the INHERITANCE concept for saving my coding time.
I would like to reuse the current controls, if possible.
 
The is really the purpose of usercontrols. Try to move those controls (and
the code logic) into a user control. Or is a usercontrol out of the
question given the current design of the application which might result in a
lot of work?
 
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?

1. Create a form frmContactBase that contains all of the common
controls and code. If you have any controls or code that need to be
accessed by the derived forms, make them protected instead of private.

2. Remove the common controls and code from frmContactAddress and
frmContactPerson.

3. Modify frmContactAddress and frmContactPerson to inherit from
frmContactBase instead of System.Windows.Forms.Form.

One thing to be wary of is that the form designer has some odd
interactions with data-bound controls, datasets, etc. If you need to
populate anything in your Load event handler or constructor, put it
inside an if statement like this:

if (false == this.DesignMode)
{
// Load data
}
 
Back
Top