Why not both?

  • Thread starter Thread starter Charlie Williams
  • Start date Start date
C

Charlie Williams

One of the main reasons for using inheritance is so you
don't have to reinvent the wheel with every app you
write. UserControls exist for you to inherit from so you
don't have to write all the plumbing code yourself, such
as notifying child controls when they should be
repainted.

Are there events fired in your custom collection when
controls are added and deleted? If so, you can use these
to update the Controls collection of the user control
whenever anything changes.

CollectionProperty.ControlAdded += new EventHandler
(ControlAdded);

void ControlAdded(object sender, EventArgs e){
this.Controls.Add(sender);
}

You don't need to use events, of course, but it would
make it easier to keep track of changes. Otherwise, just
remember to make changes to both collections whenever you
change one.

Charlie
 
One of the main reasons for using inheritance is so you don't have to
reinvent the wheel with every app > you write.

Isn't that a little bit of an exaggeration? I have been writing
applications for more years than I would like to admit, only tried OO
recently and hardly used inheritance yet, but I certainly did not re-invent
the wheel with each app I wrote, and I have - like many other people -
developed a library of common functions with lasting interfaces.

Peter Seaman
 
I say use all three, just to be sure.


Peter Seaman said:
reinvent the wheel with every app > you write.

Isn't that a little bit of an exaggeration? I have been writing
applications for more years than I would like to admit, only tried OO
recently and hardly used inheritance yet, but I certainly did not re-invent
the wheel with each app I wrote, and I have - like many other people -
developed a library of common functions with lasting interfaces.

Peter Seaman
 
Obviously, my post was supposed to a response but I
clicked the wrong button, it seems :)

I certainly did not mean to suggest that inheritance is
the only way to reuse code. The poster's question was
why the child controls in his custom control were not
being repainted when he thought they should be. The
reinvention part I was speaking of was the built-in
plumbing that container controls have to notify child
controls of such events. There's no need to write it
himself if it's already there for him to use.

Charlie
 
I have reconsidered my original position and will now
settle for no less than four
 
Back
Top