Windows Develop Bookmark and Share   
 index > Windows Forms Designer > default toolbox tab for usercontrol
 

default toolbox tab for usercontrol

Is it possible though an attribute or any other way to specify the default tab for a usercontrol to be added to the toolbox instead of defaulting to the "Windows Forms" tab? I am developing an application that implements many user controls and I would like them grouped together in the toolbox instead of mixed in with all the standard controls. any help would be appreciated. thanks.
MigrationUser 1  Monday, March 17, 2003 1:52 PM
I was just planning to ask the same question, and I hade a look on the .net 1.1 documentation, but unfortunately I did not found any attribute for that.

Instead I found many .net classes that will help you manage the toolbox items, but you must write a lot of code.

I hope, like you, if there was an attribute for that, and at the same time I am planning today to try to write my first attribute or attributes (I still don't know exactly) for the toolbox.

If I succeed I will post the code here, and I will use it for my application of course :-)
MigrationUser 1  Tuesday, March 18, 2003 8:07 AM
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.
MigrationUser 1  Tuesday, March 18, 2003 11:17 AM
Unfortunately, I just can't find any way to write a toolbox attribute as specified above, I did spend more than 7 hours today trying to solve that.

About my controls library I am planning now to write an installer to add the controls to visual studio during setup in a special tab using the code posted by me previously.
MigrationUser 1  Tuesday, March 18, 2003 6:46 PM
I really like your code, however, since I want to add this to several controls of mine, I generalized SetupToolbox and use the assembly name as toolbox category:

private void SetupToolbox()
{
ToolboxItem ixToolboxItem;
ixToolboxItem = new System.Drawing.Design.ToolboxItem(<b>this.GetType()</b>);
ixToolboxItems = ixToolboxService.GetToolboxItems(<b>this.GetType().Assembly.GetName().Name</b>);
if (ixToolboxItems.Contains(ixToolboxItem) == false)
{
ixToolboxService.AddToolboxItem(ixToolboxItem,<b>this.GetType().Assembly.GetName().Name</b>);
}
}

That easens copy'n'paste ;-) 

Regards,
Thomas
MigrationUser 1  Wednesday, March 26, 2003 1:20 PM

You can use google to search for other answers

Custom Search

More Threads

• combo box like textbox
• Bug!! VS.Net 2003 Using Designer for untyped Datasets
• Inheritence With Inheritence Picker????
• custom designer for component that inherits from ToolStripItem
• C# Web Browser/File Association - all within Windows Application
• splitting screens
• Important: Dynamically added references are working during buildtime, but not in designer mode of VS2008
• Form Controls Have Disappeared
• User Control Bug with contained PictureBox Controls?
• DataBinding listview