首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ILNumerics隐藏PlotCube

ILNumerics隐藏PlotCube
EN

Stack Overflow用户
提问于 2018-01-25 23:14:58
回答 1查看 79关注 0票数 1

我有一个场景,有两个不同的PlotCubes,它们必须单独显示。隐藏和显示PlotCubes的最佳步骤是什么?我尝试过remove,但这似乎改变了PlotCube对象。这些代码行是:

代码语言:javascript
复制
IlPanel1.Scene.add(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)  

现在,两个立方体都可见。现在我只想显示PlotCube2

代码语言:javascript
复制
IlPanel1.Scene.Remove(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)

切换回PlotCube1:

代码语言:javascript
复制
IlPanel1.Scene.Remove(PlotCube2)  
IlPanel1.Scene.add(PlotCube1)  

但这是行不通的。remove语句似乎删除了整个对象。有没有一种方法可以在不影响原始对象的情况下添加/删除LinePlots、SurfacePlots、PlotCubes等元素?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-26 00:11:44

使用plot cubeVisible属性可查看其可见性:

代码语言:javascript
复制
// 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要快得多,并且不会产生(重新)创建图形对象的相当大的成本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48446172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档