views:

248

answers:

1

I've created a control class that inherits a Panel control. This control then contains two other panels, one of which I would like to be an IContainerControl.

I know how to turn the entire control into a IContainerControl but have been unable to do the same to a child control. I've tried in both C# and VB.Net and failed with both.

Does that make sense? I tried searching but didn't find anything that helped, hopefully someone here can get me on my way!

Thanks!

edit

I'm sorry, been a long day... I'm using WinForms.

Basically I need a custom usercontrol that has two panels, one that displays some stats and the other that contains controls. The stats panel is done and working, but the other panel may contain a DataGridView, a ListView or a TreeView (whichever the user adds at design time).

And yes, I've implemented both ActiveControl and ActivateControl.

+1  A: 

I think you have two strategies here : first the "cheap stuff" :)

Cheap stuff strategy :

  1. assuming the end-user is a programmer with source, with the project open in Visual Studio or Mono, able to create UserControls, and able to drag-drop their choice of controls (such as the Treeview, or ListView, you mention) onto "whatever."

    a. create two UserControls

    b. UserControl1 contains room for two panels.

    c. on one side of UserControl1 insert a Panel, and design it to spec.

    d. on UserControl2 : allow the end-user to insert the control of their choice : TreeView, etc.

    e. build both UserControls

    f. place an instance of UserControl2 (from the ToolBox icon) onto UserControl1 and position it (Dock, Anchor, whatever) as you wish.

Build again. Now you can place an instance of UserControl1 on a WinForm, and it will include both Panels.

Costs/Benefits :

  • you can edit the appearance and properties of each control in the standard way

  • the end-user can choose which Control to go on UserControl2.

  • you've got a greater separation of components here that may allow greater ease of maintenance or extension ?

  • who's going to do the programming based on whether the user chose a TreeView or a ListView for the Control to go on UserControl2 ?

More Expensive Stragegy

You are going to need to get into inheriting from 'ParentControlDesigner to make a run-time placed control that is a container placed inside another container accept design-time drag-drop of controls.

Fortunately, there's a good article by Henry Minute on CodeProject with C# source : Designing Nested Controls Strongly suggest you read the comments by Sacha Barber at the bottom of this article and the answers by Henry Minute.

And also see, here on SO : Adding design-time support for a nested container in a custom/usercontrol (Winforms).

In either strategy you'll have some work to do to enable access (what properties you expose, what events you raise "up" to enclosing containers, etc.).

BillW
Thank you! Between those two links you provided I think I can figure something out.
Fuod