control, usercontrol, panel

Many times I don't know what control to derive from.  For example, if I want a control that will just have two docked panels on it, what's a good choice   Also I noticed that TabControl derives from Control even though it has child controls and I thought panel would be a good choice.

Answer this question

control, usercontrol, panel

  • John Koerner

    It depends on which methods and properties you want to write by yourself and which you want the object to handle.

    The control class mostly used for owner-drawen one perpose element, that you want to write from scrach.

    example for this is an owner-drawn button writing from scrach.

    panel is a base containr and to create control with containr abilties, it is common to use it (even due you can do this also by a control or user control).

    example for this is a panel with some kind of header on it.

    The user control mostly used for heavier controls, which have more than one control and you want to combine their properties and methods.

    example for this is a control with textbox and button on it.

    anyway, you can do everything on each of this controls...



  • vetlinda

    Just take a good look at all the controls that .NET offers and see which behaviour suits your purpose right. The Control class is the base class for all controls. If you want 100 percent customization, like building your own control, you will want to derive from Control. If you would like to have controls with autoscroll behaviour, you might want to derive from ScrollableControl. If you are planning to create controls that can have child controls dropped onto them, you might want to use ContainerControl as a base class. Panel adds a bit of functionality to ContainerControl, like the painting of the borders. UserControl is a control that can have child controls. This is a very convenient way of creating a custom control simply by composing a set of other controls.

    Your want a control with two panels on it. Are you aware that the SplitContainer from .NET 2.0 is also a control with two panels and a splitter inbetween of them If that does not work for you, I would use UserControl.

    If you have any specific uses for a control, check these classes and see what their function is. If you can't find the best control, ask us specific questions on what you are trying to achieve and what the best base class would be.



  • control, usercontrol, panel