In response to a request on the forum I have expanded the options available for importing and exporting KyptonPalette definitions.
In the current release you have only one option for saving and loading a palette definition. You must save to an xml file. But this makes it difficult to handle a couple of the most common real world requirements.
Database Storage
There are now Export and Import overrides that operate on arrays of bytes. So calling the appropriate version of Export will return i>byte[]. This is easy to then store in a database of your choice.
If you prefer to store it in your database as a string type rather than as raw bytes then you can always call Convert.ToBase64String(…) first. Then use the Convert.FromBase64String(…) to convert it back to an array of bytes for the Import call.
If instead of a database you are using your own persistence mechanism then the option of using the byte array or converted Base64 string allows you to integrate the palette information.
Embedded Palettes
A second likely scenario is that you have a palette definition file you created using the PaletteDesigner and would like to distribute it with your application and have it loaded and used at runtime.
This is where the second set of Export and Import overloads come into play. They both take a Stream instance as the source for loading from or saving into. To import using this overload from an embedded resource just do the following.
- Add your palette xml file to the project.
- Mark the file as an ‘Embedded Resource’.
- Use the following code to load the resource.
Assembly a = Assembly.GetAssembly(typeof(MyForm));
Stream s = a.GetManifestResourceStream("MyForm.Resources.Palette.xml");
kryptonPalette1.Import(s);
I will add a little tutorial to the next release that gives more detailed step by step instructions on embedding a palette definitions. But as you can see it is pretty trivial.