Forms and UserControls, New to C#

  • Thread starter Thread starter Johnny Fugazzi
  • Start date Start date
J

Johnny Fugazzi

I am working on a basic windows for App using c# and vs.net2003.

I have a usercontrol containing a treeview, and I need to display things on
he main form based on the item selected in the treeview. What is the
bestway to reference the panel (or other controls) on the main form from the
UserControl?
 
A good principle for questions like this is that of loose-coupling. It's
generally a good idea for a user control to know little or nothing about
where it's sited. Better, I think, to raise custom events to the owner when
something interesting happens, and let the owner take whatever action is
appropriate, such as updating the contents of other controls on the form.
This gives you the freedom of making changes to the form without having to
modify the user control's code, and lets the parent form encapsulate all
information about its logic and behavior.

HTH,
Tom Dacon
Dacon Software Consulting
 
Sounds like it makes sense.
Do you have a good reference or place for information to look into this?
Like I mentioned, I am new to using C# in a windowsForms environment. I
have mostly worked with vb.net in asp.net environments in the past.
 
You might look around for a good text on the principles of object-oriented
design. This isn't really a language issue - the principles apply to VB just
as firmly as they apply to C# or C++ or SmallTalk or any other
object-oriented language. In fact, if you were to do a search for such a
book, I'd look for something that didn't concentrate on a single language so
much as it emphasized the language-independent principles.

Sorry I don't have a specific recommendation. I've been doing this for so
long that the primary references I used when I was integrating these
principles are kind of dated now.

I will say, however, that Microsoft's MSDN library and the sample code that
you find there are not necessarily the best examples of good object-oriented
design that you'll come across. So don't take what you find there as gospel.

Best of luck,
Tom Dacon
Dacon Software Consulting
 
Back
Top