To Enable / Disable Automatic Template Creation
The easiest way to customize the contents of your application's toolbox is to disable the automatic creation of templates. The Project component has a AutoCreateTemplates property that specifies whether a template should be created automatically for each ShapeType of the loaded shape library.
1. | Select the Project component and set its AutoGenerateTemplates property to false. |
ToolBox content with AutoGenerateTemplates enabled.
|
|
ToolBox content with AutoGenerateTemplates disabled.
|
2. | Create a new project and load the shape libraries. |
project1.LibrarySearchPaths.Add(Application.StartupPath);
project1.Name = "My NShape Project";
project1.Create();
project1.AddLibraryByFilePath(Path.Combine(Application.StartupPath, "Dataweb.NShape.GeneralShapes.dll"));
|
3. | Create a pointer tool and add it to the ToolSetController. Typically, the pointer tool is added as the "default tool". The default tool is specifies the tool that is selected automatically after another tool was executed. |
toolSetController1.AddTool(new PointerTool(), true);
|
4. | Create templates and add them to the repository. |
Circle circle = (Circle)project1.ShapeTypes["Circle"].CreateInstance();
// Specify the permission set for all shapes created from this template
circle.SecurityDomainName = 'B';
circle.FillStyle = project1.Design.FillStyles.Red;
circle.LineStyle = project1.Design.LineStyles["MyCustomLineStyle"];
project1.Repository.InsertTemplate(new Template("Circle", circle));
|
5. | Start your application and check the result. Your toolbox should now contain only two items: The pointer tool and a circle. |
Customized ToolBox controls with only a pointer tool and a circle.