Hello
Is it possible to switch panels after registering? To clarify a little:
I have a few different panels for different commands. Lets say for now three:
General panel visible after loading the plugin:
public partial class Panel1 : UserControl
Panel to be used after calling command2
public partial class Panel2 : UserControl
Panel to be used after calling command3
public partial class Panel3 : UserControl
Then I would like to change panelType=typeof(Panel1) to panelType=typeof(Panel2) when command2 is called. So instead of Panel1 Panel2 will be visible in the same docked tab. Only one panel is displayed at once.
And of course similar for Panel3 and command3 etc.
OpenPanelAsSibling does not work for me as it will make me add like ten panels which will be a mess. And I want the user to be able to open only Panel1 without using commands provided by me.
Just to clarify: you have a single panel, and you want his single panel to display a different user control based on what command is run. Is this correct?
I haven’t tried this. But it might be as easy as keeping reference to all three user controls (on your plug-in object) and then just showing and hiding what panel you want (per what command is run).
public void ShowUserControl(int control)
{
if (0 == control)
{
m_user_control_0.Show();
m_user_control_1.Hide();
m_user_control_2.Hide();
}
else
{
// etc...
}
}
Thank you for your answer. That is indeed what I would like to have. The panel should be showing panel1 when no command has been run and a different panel depending on the command run. I tried to implement your solution but I couldn’t make it work.
My code for plugin file is this:
public class MyProject2PlugIn : Rhino.PlugIns.PlugIn
{
public MyProject2PlugIn()
{ Instance = this;} }
public static MyProject2PlugIn Instance
{get; private set; }
protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage)
{
System.Type panelType = typeof(panel1);
Rhino.UI.Panels.RegisterPanel(this, panelType, "PluginPanel", System.Drawing.SystemIcons.Question);
//Panel code
Guid panelId = panel1.PanelId;
bool bVisible = Rhino.UI.Panels.IsPanelVisible(panelId);
if (bVisible != true)
{
Rhino.UI.Panels.OpenPanel(panelId);
}
return Rhino.PlugIns.LoadReturnCode.Success;
}
}
public class PanelShowClass
{
private panel1 m_panel1;
private panel2 m_panel2;
public void ShowUserControl(int control)
{
panel1 pan1 = new panel1();
m_panel1 = (panel1)pan1._panel1;
panel2 pan2 = new panel2();
m_panel2 = (panel2)pan2._panel2;
if (0 == control)
{
m_panel1.Show();
m_panel2.Hide();
}
else
{
m_panel1.Hide();
m_panel2.Show();
}
}
}
}
The command:
namespace MyProject2
{
[System.Runtime.InteropServices.Guid("4fc41565-107f-4af2-ba17-9ffa4a8eb806")]
public class MyProject2Command : Command
{
public MyProject2Command()
{ Instance = this;}
public static MyProject2Command Instance
{get; private set;}
public override string EnglishName
{get { return "MyProject2Command"; }}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
PanelShowClass Cos = new PanelShowClass();
Cos.ShowUserControl(1);
return Result.Success;
}
}
}
And typical panel code:
namespace MyProject2
{
[System.Runtime.InteropServices.Guid("83D6FCC8-4F31-4AE3-BF60-C6528DB232D5")]
public partial class panel1 : UserControl
{
public panel1()
{InitializeComponent();}
public static System.Guid PanelId
{
get
{
return typeof(panel1).GUID;
}
}
public UserControl _panel1
{
get { return this; }
}
}
}
To be honest I have no idea how it could work as I do not pass information about referenced panel at all.