How to use designer with custom controls

Topics: CAB & Smart Client Software Factory
Oct 11, 2005 at 1:51 PM
originally posted by: jnyikos

Please bear with me, I'm a newbie!

I've created a custom combobox user control that has a service dependency. I want to be able to use the designer to place the combobox onto another "SmartPart" enabled user control such that the combo box will inherit the services provided by that user control. Right now, I have it working, but I have to programmatically add the combobox -- is there a way to allow this to work thru the designer? If I try and use the designer to drop my combobox, my services do not work within the combobox. I've included excerpts of my code below:

public partial class CustomComboBox : System.Windows.Forms.ComboBox
{
ServiceDependency
private ISmartContainerService mySmartContainer = null;
}

public partial class TestView: UserControl, ISmartPartInfoProvider
{
Controller
TestController myController = null;

private void TestView_Load(object sender, EventArgs e)
{
// Ideally would like to create the comboxbox via designer and not here
CustomComboBox combo = myController.Create<CustomComboBox>();

combo.Location = new System.Drawing.Point(85, 12);
combo.Name = "myComboBox";
combo.Size = new System.Drawing.Size(110, 21);

this.Controls.Add(combo);
}
}

public class TestController : Controller
{
ServiceDependency
private ISmartContainerService mySmartContainer = null;

public T Create<T>() where T : new()
{
return this.WorkItem.Create<T>();
}
}