NShape Programmer Tasks
Loading a Template Project

<< Click to Display Table of Contents >>

Navigation:  Programmer Tasks > Customizing the Toolbox >

NShape Programmer Tasks
Loading a Template Project

Previous pageReturn to chapter overviewNext page

To Load a Predefined Template Project

An other way to easily customize the contents of the user's toolbox is to create a project containing all templates the user should work with. This has the useful side effect that you can modify the toolbox contents without rebuilding your application. The disadvantage is that any person knowing where to find the template file, can easily modify it and - worst case - outmaneuvering your predefined permission restrictions.

1.Start the NShape Designer (or an other tool), load all needed shape libraries and edit the templates in the toolbox. Delete all templates you don't need.

2.Save the project to disk.

3.Copy it to a location where your application can access it.

4.Set the AutoGenerateTemplates property of the Project component to false.

5.Load the project while your application is starting (after all components and controls have been created).

// Load the predefined template project
string templateProjectPath = @"C:\Users\Public\Documents\NShape\Demo Projects\Railway Network.nspj";
xmlStore1.DirectoryName = Path.GetDirectoryName(templateProjectPath);
xmlStore1.FileExtension = Path.GetExtension(templateProjectPath);
project1.Name = Path.GetFileNameWithoutExtension(templateProjectPath);
project1.Open();

6.After the project has been loaded, switch the store location in order to prevent the template project is being overwritten when hitting the "Save" button.

// Change the store's location 
xmlStore.DirectoryName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
xmlStore.FileExtension = ".nspj";
project.Name = "My New Project";