views:

60

answers:

2
A: 

If you are meaning that you would like the custom control to behave like a container (like a groupbox normally does) then you need to let the control and the designer know how it should be treated.

Remember to implement IContainerControl and decorate the object with the appropriate designer attribute for designer container support IE:

[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))]
Quintin Robinson
Thanks, this is also useful. But for my problem, it behaves like a groupbox, but it covers the controls inside of it. I can see them in the designer but when you run the tool, they appear behind the composite control.
Joan Venge
A: 

It is possible Quintin is right, and that something is going wrong with the desginer support of your control, that is, you've created ControlA, and are extending it to ControlB by adding a button at design time. When you instatiate ControlB, the button is not visible.

Can you verify at runtime, using breakpoints/asserts/etc that:`

  1. ChildButton exists.
  2. ChildButton is a member of CompositeControl.Controls.
  3. ChildButton location is 'in-view' of the CompositeControl.
  4. ChildButton is visible.

If it were me, I'd set a breakpoint in the constructor of the control, and ride into InitializeComponent(), checking that everything is created and added correctly. If ChildButton exists, and has a reference in CompositeControl.Controls and its location is in-view, then I'm at a loss to explain why it's not showing.

Charlie Salts
Thanks, if I am not wrong, you are thinking ChildButton is part of the composite control? Because it's not. The composite control is made up of 2 controls: 1 checkbox, 1 groupbox. But later when I use this composite control and place some controls on it, as a user, the controls only show up at the top at design time.
Joan Venge
Yes, I knew you meant that. I'm starting to think designer support for your control is broken. When you step through the code as your CompositeControl is initialized, check that everything should be as you expect. As a last resort, you could try adding the button to your control at runtime, to verify that it does show correctly. If it does, then you know you've got a designer issue.
Charlie Salts
Thanks, if it's a designer issue, would it be fixed?
Joan Venge
If you've implemented Quintin's suggestion, there's not much more that I can suggest.
Charlie Salts