To get this "extra" functionality in design-time for your control, you need
to have a designer (System.Wen.UI.Design.ControlDesigner), and don't forget
to apply the DesignerAttribute to your control. The designer's code requests
a IComponentChangeService and subscribes to its ComponentAdding event. That's
all.
So, in my case the designer looks like this:
class CMSWebPageDesigner : ControlDesigner
{
private IComponentChangeService changeService = null;
private void InitializeServices()
{
this.changeService = GetService(typeof(IComponentChangeService))
as IComponentChangeService;
if (changeService != null)
{
changeService.ComponentAdding += new
ComponentEventHandler(ChangeService_ComponentAdding);
}
}
void ChangeService_ComponentAdding(object sender, ComponentEventArgs
e)
{
if (e.Component is CMSWebPage)
throw new ApplicationException("CMSWebPage component is
already on the page.");
}
#region Overrides
public override bool AllowResize
{
get
{
return false;
}
}
private DesignerVerbCollection designTimeVerbs;
public override DesignerVerbCollection Verbs
{
get
{
if (null == designTimeVerbs)
{
designTimeVerbs = new DesignerVerbCollection();
designTimeVerbs.Add(new DesignerVerb("Page Setup...",
new EventHandler(this.OnPageSetup)));
}
return designTimeVerbs;
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.changeService != null)
{
// Unhook event handlers.
this.changeService.ComponentAdding -=
new ComponentEventHandler(
ChangeService_ComponentAdding);
}
}
base.Dispose(disposing);
}
public override void Initialize(IComponent component)
{
if (!(component is CMSWebPage))
throw new ArgumentException("Must be a CMSWebPage component");
base.Initialize(component);
InitializeServices();
}
#endregion
private void OnPageSetup(object sender, EventArgs e)
{
PageDesignerEditor editor = new PageDesignerEditor();
editor.EditComponent(Component);
}
}