Intro
Krypton Suite is an awesome free controls library for Winforms. It’s presently being maintained/expanded by some good souls. You can check it out here: GitHub
Unfortunately, the documentation is somewhat lacking. Particularly for the Docking feature. Thus, I thought I’d keep a record of my discoveries whilst figuring this library out.
Getting started
Install the relevant Krypton Libraries from nuget. Start with a basic windows form. Then add KryptonManager and DockingManager to the form. Add a KryptonPanel to the form and a child KryptonDockableWorkspace.
To instantiate docking, do the following:
|
1 2 3 4 5 6 |
private void Form1_Load(object sender, EventArgs e) { KryptonDockingWorkspace w = dockingManager.ManageWorkspace("Workspace", kryptonDockableWorkspace1); dockingManager.ManageControl("Control", kryptonPanel1, w); dockingManager.ManageFloating("Floating", this); } |
Then, to add dockable windows (they are called “Pages” in Krypton), include the following method:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private KryptonPage NewPage(Control control, string controlName) { // Create and uniquely name the page KryptonPage page = new KryptonPage(); page.Text = controlName; page.TextTitle = page.Text; page.UniqueName = page.Text; control.Dock = DockStyle.Fill; page.Controls.Add(control); return page; } |
You can add a window via various methods, all under DockingManager.Addxxx. The two covered here are to ‘DockSpace’ and to ‘Workspace’ The former is traditional tool window docking and the latter is akin to multi-instance document/workpiece docking (think code in Visual Studio or Images in Photoshop). You basically just send a control to the above method. These controls can be UserControls – the best way to achieve different views:
|
1 2 3 |
dockingManager.AddDockspace("Control", DockingEdge.Left, new KryptonPage[] { NewPage(new ListView(), "Selector") }); dockingManager.AddDockspace("Control", DockingEdge.Right, new KryptonPage[] { NewPage(new PropertyGrid(), "Properites") }); dockingManager.AddToWorkspace("Workspace", new KryptonPage[] { NewPage(new RichTextBox(), "Text Document 1"), NewPage(new RichTextBox(), "Text Document") }); |
Focussing a Page
This was a bit of a tricky one. Basically, you need to find the parent Cell of the Page and then set its SelectedPage to the Page you want focussed. A method to assist:
|
1 2 3 4 5 |
private void ShowPage(KryptonPage kryptonPage) { var pageParent = kryptonPage.KryptonParentContainer; ((dynamic)pageParent).SelectedPage = kryptonPage; } |
Useful Members
| Member | Function | Notes |
| KryptonDockableWorkspace.ActivePageChanged | Event fired when Page is changed | EventArgs provide old and new Page |
Glossary
| Krypton Term | Function | Notes |
| Page | An individual dockable window | |
| Cell | That in which numerous Pages are stacked (e.g. tabbed documents or tool windows) | |

Leave a Reply