Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Designer(typeof(DesignerEventsDesigner))]
- public class DesignerEvents : WebControl
- {
- }
- public class DesignerEventsDesigner : ControlDesigner
- {
- private string controlAddedID, controlRemovedID;
- private bool designerActive;
- public override void Initialize(IComponent component)
- {
- base.Initialize(component);
- //Hook our events
- HookDesignerEvents();
- }
- public override string GetDesignTimeHtml()
- {
- //Grab our control
- DesignerEvents control = (Component as DesignerEvents);
- //Check to see if our control has a width, if not set it.
- if (control.Width.IsEmpty) control.Width = 300;
- string html = "<div id='" + control.ID +"' style='height: " + control.Height
- + "; width: " + control.Width + "'>ControlAdded: " + controlAddedID
- + "<br>ControlRemoved: " + controlRemovedID
- + "<br>DesignerActivated: " + designerActive.ToString()
- + "</div>";
- return html;
- }
- public void HookDesignerEvents()
- {
- //Get the IDesignerHost
- IDesignerHost host = Component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
- //Get the component event service
- IComponentChangeService componentService = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
- //Hook our events
- host.Activated += new EventHandler(host_Activated);
- componentService.ComponentAdded += new ComponentEventHandler(componentService_ComponentAdded);
- componentService.ComponentRemoved += new ComponentEventHandler(componentService_ComponentRemoved);
- }
- void componentService_ComponentRemoved(object sender, ComponentEventArgs e)
- {
- controlRemovedID = e.Component.Site.Name;
- UpdateDesignTimeHtml();
- }
- void componentService_ComponentAdded(object sender, ComponentEventArgs e)
- {
- controlAddedID = e.Component.Site.Name;
- UpdateDesignTimeHtml();
- }
- void host_Activated(object sender, EventArgs e)
- {
- designerActive = true;
- UpdateDesignTimeHtml();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement