Intercept when my control dropped on a WebForm

V

Vipeo

Hi All!

I need to intercept the event when my control dropped on a WebForm (or
manually added by changin page's source HTML). I know about
IComponentChangeService and its ComponentAdding event, but in which class
should I use it?

Thank you for any help.
 
V

Vipeo

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top