我有一个场景,有两个不同的PlotCubes,它们必须单独显示。隐藏和显示PlotCubes的最佳步骤是什么?我尝试过remove,但这似乎改变了PlotCube对象。这些代码行是:
IlPanel1.Scene.add(PlotCube1)
IlPanel1.Scene.add(PlotCube2) 现在,两个立方体都可见。现在我只想显示PlotCube2:
IlPanel1.Scene.Remove(PlotCube1)
IlPanel1.Scene.add(PlotCube2)切换回PlotCube1:
IlPanel1.Scene.Remove(PlotCube2)
IlPanel1.Scene.add(PlotCube1) 但这是行不通的。remove语句似乎删除了整个对象。有没有一种方法可以在不影响原始对象的情况下添加/删除LinePlots、SurfacePlots、PlotCubes等元素?
发布于 2018-01-26 00:11:44
// stores the current state. (You may even use one of the ILPlotCube.Visible flags directly)
bool m_panelState = false;
// give the plot cubes unique tags so we can find them later.
private void ilPanel1_Load(object sender, EventArgs e) {
ilPanel1.Scene.Add(new ILPlotCube("plotcube1") {
Plots = {
Shapes.Circle100, // just some arbitrary content
new ILLabel("Plot Cube 1")
},
// first plot cube starts invisible
Visible = false
});
ilPanel1.Scene.Add(new ILPlotCube("plotcube2") {
Plots = {
Shapes.Hemisphere, // just some content
new ILLabel("Plot Cube 2")
}
});
}
// a button is used to switch between the plot cubes
private void button1_Click(object sender, EventArgs e) {
m_panelState = !m_panelState;
SetState();
}
// both plot cubes are made (un)visible depending on the value of the state variable
private void SetState() {
ilPanel1.Scene.First<ILPlotCube>("plotcube1").Visible = m_panelState;
ilPanel1.Scene.First<ILPlotCube>("plotcube2").Visible = !m_panelState;
ilPanel1.Refresh();
}重要的部分是在面板上调用Refresh(),以便立即显示修改。
请注意,通常情况下,如果以后可能再次需要绘制对象,最好将它们保留在周围。而不是从场景图中删除它们,然后重新创建类似的对象,将对象设置为Visible = false要快得多,并且不会产生(重新)创建图形对象的相当大的成本。
https://stackoverflow.com/questions/48446172
复制相似问题