I found how to manage the toolbox from my control, it is simple
This code added to your control may help little bit (the control name is axButton)
Global variables: private IToolboxService ixToolboxService = null; private ToolboxItemCollection ixToolboxItems;
/// <summary> /// Obtain or reset IToolboxService reference on each siting of control. /// </summary> public override System.ComponentModel.ISite Site { get { return base.Site; } set { base.Site = value; // If the component was sited, attempt to obtain // an IToolboxService instance. if( base.Site != null ) { ixToolboxService = (IToolboxService)this.GetService(typeof(IToolboxService)); if( ixToolboxService != null ) { SetupToolbox(); } } else { ixToolboxService = null; } } }
private void SetupToolbox() { ToolboxItem ixToolboxItem; ixToolboxItem = new ToolboxItem(typeof(axButton)); ixToolboxItems = ixToolboxService.GetToolboxItems("Ax Controls"); if (ixToolboxItems.Contains(ixToolboxItem) == false) { ixToolboxService.AddToolboxItem(ixToolboxItem,"Ax Controls"); } }
This code added to your user control will create a toolbox category and a tool box item for your control, as soon as you drag the control to the form :-)
I've created it using the .net 1.1 help files
I must find now how to modify this code to a control designer, and how to modify the control designer to an attribute, and of course how to make the attribute work at design time directly, so I don’t need to place the control on the form in order to add it in a new group, how this can happen during the normal VS.NET use.
|