In This Topic
    Layers
    In This Topic
    Layers are the primary diagram element containers, which can be used to logically group related elements. Typically layers contain only shapes, but can also contain other types of diagram elements (including other layers). The content of each drawing is organized in layers. Each layer is represented by an instance of the NLayer class.
     Active layer

    Of all layers currently existing in a drawing only one can be active at a time. The currently active layer can be obtained from the ActiveLayer property of the NDrawingDocument class. For example:

    C#
    Copy Code
    // obtain the document active layer
    NLayer activeLayer = document.ActiveLayer;
    
    Visual Basic
    Copy Code
    ' obtain the document active layer
    Dim activeLayer As NLayer = document.ActiveLayer
    

    Drawings can have multiple layers, which are accessible from the Layers property. The active layer for a drawing is specified by the ActiveLayerUniqueId property of the NDrawingDocument class. The following code adds a new layer to a drawing document and makes it the currently active one:

    C#
    Copy Code
    // create a new layer and make it the active one
    NLayer layer = new NLayer();
    drawingDocument.Layers.AddChild(layer);
    drawingDocument.Layers.ActiveLayerUniqueId = layer.UniqueId;
    
    Visual Basic
    Copy Code
    ' create a new layer and make it the active one
    Dim layer As New NLayer
    drawingDocument.Layers.AddChild(layer)
    drawingDocument.Layers.ActiveLayerUniqueId = layer.UniqueId
    
    Drawing views by default modify the content of the currently active layer. This helps you focus on the concrete active layer content.
     Layer features

    Layers implement the following features:

    • Painting - layers implement the INPaintable interface. The implementation delegates the painting to the layer children. The layer visibility is controlled from its Visible property.
      C#
      Copy Code
      // hide the active layer
      drawingDocument.ActiveLayer.Visible = false;
      
      Visual Basic
      Copy Code
      ' hide the active layer
      drawingDocument.ActiveLayer.Visible = False
      
    • Shadows - object shadows can be cast on a per layer basis. For example:
      C#
      Copy Code
      // cast object shadows behind all nodes in this layer
      drawingDocument.ShadowsZOrder = ShadowsZOrder.BehindLayer;
      
      Visual Basic
      Copy Code
      ' cast object shadows behind all nodes in this layer
      drawingDocument.ShadowsZOrder = ShadowsZOrder.BehindLayer
      
    • Hit Tests  - you can hit test only the elements, which reside in a particular layer, hence NLayer implements the INHitTest interface.
     Related Examples
    Windows Forms: Document Object Model - Layers folder 
    See Also