Form inheritence

  • Thread starter Thread starter Alan T
  • Start date Start date
Right click on the project, than select "Add new Item". Now, you can
select the inherited usercontrol icon or inherited winfrom icon from
"Add new Item" dialog.(Make sure that you select UI node in the left
treeview on the dialog).

Sincerely,
simida
 
Right click on the project, than select "Add new Item". Now, you can
select the inherited usercontrol icon or inherited winfrom icon from
"Add new Item" dialog.(Make sure that you select UI node in the left
treeview on the dialog).

Sincerely,
simida


In my experience visual inheritance is somewhat flaky. Be sure to save
& build your project immediately after making any changes to base
forms. I usually create my subclassed forms simply by adding a new
form then changing the inheritance specifier in the Form.cs file:

from MyForm : Form
to MyForm : MyBaseForm

I find this more reliable than using the Add New Item -> Inherited
Form option. It often crashes for me...sigh...
 
Will the controls appear on the inherited form?

Yes. Remember that if you want to code against them in the inherited
form you will need to change their modifier to be "protected". It
defaults to private. Whenever you change anything on the base form the
IDE usually displays a little message in the status bar that says "you
must rebuild your project before any changes will be picked up by
child forms open in the designer."

Now would probably be a good time to mention that there are other
drawbacks to visual inheritance apart from the reliability of the IDE
which you will soon come up against. The biggest problem I have is
that some common controls, such as the DataGridView, do not "play
nice" with the IDE. Microsoft has marked the control as "locked under
visual inheritance". What this means is that you can't change any
properties (or add any event handlers) *in the designer* on the
inherited form. You can do it in code, but it is annoying to say the
least to be unable to add an extra column, change a heading or width
etc.

That said, visual inheritance is rather cool, and when combined with
standard class inheritance it can save a lot of coding and time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top