In my previous blog Rhino C# Development (III) : Add Winform UI to Rhino, I demonstrated how to create a dock bar with Winform User controls in Rhino3D.
In this blog I am to demonstrate how to use a similar approach to create Rhino panels, and then dock the panels side-by-side. Rhino panels, are tabbed containers where collection of controls can be hosted, as shown below.
![tabbedpanel-001.png]()
To create such a panel, in Visual Studio, add a user control in the plugin project. If you don’t know how to create such a plugin project, refer to my previous blogs for details.
In this example, a UserControl called GeometryPanel is inserted into the project, and a few simple winform controls are added for illustrative purposes. Add a Guid attribute to the UserControl, as shown below.
![image image]()
[System.Runtime.InteropServices.Guid("0b0c3a6e-7efb-47c9-b2e3-7d92788a9f74")]
public class MyPanelCommand : Command
{
public MyPanelCommand()
{
Instance = this;
}
}
Next, in the rhino command class, add below code lines:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var type = typeof(GeometryPanel);
Rhino.UI.Panels.OpenPanel(type.GUID);
return Result.Success;
}
Build and Run. You will see nothing if your run your command in Rhino3D. Fear not. We missed an important step: to register this panel with Rhino! In the rhino plugin class, in the constructor function, add below code lines:
public MyPanelPlugIn()
{
Instance = this;
Rhino.UI.Panels.RegisterPanel(this, typeof(GeometryPanel), “Geometry“,
Properties.Resources.Geometry);
}
Rebuild and run! Yeah! When we run the command, we can see our user control based panel inside Rhino3D!
![image image]()
OK, let’s walk one step further. Let’s dock our panel side by side with Layers Panel, to do so, modify the RunCommand function above as follows:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var type = typeof(GeometryPanel);
//Rhino.UI.Panels.OpenPanel(type.GUID);
Rhino.UI.Panels.OpenPanelAsSibling(type.GUID, PanelIds.Layers);
return Result.Success;
}
Here, we used another static field PanelIds.Layers, which refers to the Guid of the Layers panel, and indicating that we wish to dock our custom panel with the Layers panel.
![image image]()
That is it! Happy coding!
Filed under:
CAD,
Dotnet/C#,
General Tagged:
.net,
C#,
dock,
panel,
Rhino,
rhino common,
Rhino.net,
Rhino3d,
side by side,
user control,
Winform