//-------------------------------------------------------------------------
        // Rebuild the layers control. This is usually done after a picture change
        //-------------------------------------------------------------------------
        public void RebuildLayerControls()
        {
            // Delete current layer controls

            SuspendDraw.Suspend(LayerDisplayPanel); //suspend redraw to reduce lag
            //LayerDisplayPanel.SuspendLayout();
            LayerDisplayPanel.Controls.Clear();
            m_layerControls.Clear();
            // Cycle through each layer
            List<LayerControl> controls = new List<LayerControl>();
            foreach (Layer layer in m_canvasSession.GetPicture().layers)
            {
                LayerControl lc = new LayerControl(layer.Name, layer.ID);
                lc.layerNameChanged += new LayerNameChaged(OnLayerNameChange);
                lc.layerControlSelected += new LayerControlSelected(OnLayerSelectionChange);
                lc.layerDragStart += LayerControl_StartDrag;
                m_layerControls.Add(lc.GetLayerID(), lc);
                this.LayerDisplayPanel.Controls.Add(lc);
                controls.Add(lc);
            }
            foreach (Layer layer in m_canvasSession.GetPicture().layers) {
                UpdateThumbnail(layer.ID);
            }
            if (m_layerControls.ContainsKey(selectedIndex)) {
                OnLayerSelectionChange(m_layerControls[selectedIndex]);
            }
            //LayerDisplayPanel.ResumeLayout();
            SuspendDraw.Resume(LayerDisplayPanel);
        }
        //-------------------------------------------------------------------------
        // Rebuild the layers control. This is usually done after a picture change
        //-------------------------------------------------------------------------
        public void RebuildLayerControls()
        {
            // Delete current layer controls

            SuspendDraw.Suspend(LayerDisplayPanel); //suspend redraw to reduce lag
            //LayerDisplayPanel.SuspendLayout();
            LayerDisplayPanel.Controls.Clear();
            m_layerControls.Clear();
            // Cycle through each layer
            List <LayerControl> controls = new List <LayerControl>();

            foreach (Layer layer in m_canvasSession.GetPicture().layers)
            {
                LayerControl lc = new LayerControl(layer.Name, layer.ID);
                lc.layerNameChanged     += new LayerNameChaged(OnLayerNameChange);
                lc.layerControlSelected += new LayerControlSelected(OnLayerSelectionChange);
                lc.layerDragStart       += LayerControl_StartDrag;
                m_layerControls.Add(lc.GetLayerID(), lc);
                this.LayerDisplayPanel.Controls.Add(lc);
                controls.Add(lc);
            }
            foreach (Layer layer in m_canvasSession.GetPicture().layers)
            {
                UpdateThumbnail(layer.ID);
            }
            if (selectedIndex != null && m_layerControls.ContainsKey(selectedIndex))
            {
                OnLayerSelectionChange(m_layerControls[selectedIndex]);
            }
            //LayerDisplayPanel.ResumeLayout();
            SuspendDraw.Resume(LayerDisplayPanel);
        }
 //-------------------------------------------------------------------------
 // Event handler for a layer selection event
 //-------------------------------------------------------------------------
 private void OnLayerSelectionChange(LayerControl layerControl)
 {
     selectedIndex = layerControl.GetLayerID();
     foreach (LayerControl lc in m_layerControls.Values)
     {
         if (lc == layerControl)
         {
             lc.LayerActivated();
         }
         else
         {
             lc.LayerDeactivated();
         }
     }
 }
 //-------------------------------------------------------------------------
 // Event handler for a layer selection event
 //-------------------------------------------------------------------------
 private void OnLayerSelectionChange(LayerControl layerControl)
 {
     selectedIndex = layerControl.GetLayerID();
     foreach(LayerControl lc in m_layerControls.Values)
     {
         if (lc == layerControl)
             lc.LayerActivated();
         else
             lc.LayerDeactivated();
     }
 }