public void NestedContainerTest() { Control control = (Control)_helper.CreateControl(typeof(TestButton), null); Control nestedControl = new TestButton(); // The following two tests show that the DT Site: // * offers the added site-specific services via IServiceProvider // * doesn't offer its implementation of IServiceContainer as a site-specific service // * GetService is routed through the owner // INestedContainer nestedContainer = control.Site.GetService(typeof(INestedContainer)) as INestedContainer; nestedContainer.Add(nestedControl); ((IServiceContainer)nestedControl.Site).AddService(typeof(DesignSurfaceTest), new DesignSurfaceTest()); Assert.IsNotNull(nestedControl.Site.GetService(typeof(DesignSurfaceTest)), "#1"); Assert.AreEqual(nestedControl.Site.GetService(typeof(IServiceContainer)), _helper.DesignSurface.GetService(typeof(IServiceContainer)), "#2"); Assert.IsNotNull(nestedControl.Site.GetService(typeof(DesignSurface)), "#3"); }
protected bool EnableDesignMode(Control child, string name) { if (name == null) { throw new ArgumentNullException("name"); } if (child == null) { throw new ArgumentNullException("child"); } bool success = false; INestedContainer nestedContainer = this.GetService(typeof(INestedContainer)) as INestedContainer; if (nestedContainer != null) { nestedContainer.Add(child, name); success = true; } return(success); }