briscoe

IGraphicsContainter BringToFront

Discussion created by briscoe on Jun 3, 2011
I'm creating a MapControl with text labels over simple markers.  Occasionally, I don't see the text labels.  I assume the text labels are underneath the markers (they are both in the same layer).  I want to use the IGraphicsControl BringToFront method to make sure the text elements are in front of the markers.  I implemented a class that inherits from the IEnumElement interface. I use this class to store all the text elements and then pass the collection to BringToFront.  The issue seems to be that BringToFront endlessly calls the Next method even when I return a null because there are no more elements.  My question is, is the behavior of the Next method for IEnumElements suppose to return a NULL when there is not another element in the list?  I can find no documentation on the proper return value when your reach the end of the list.  If not then what is the proper return value so BringToFront will exit and execution can continue.  Here is my IEnumElements class:

    /// <summary>
    /// A collection of element objects.  This class is needed to be used with
    /// the BringToFront method of IGraphicsContainer thus the inheritance from IEnumElment
    /// </summary>
    class ElementCollectionClass : IEnumElement 
    {
        private ArrayList m_collection = new ArrayList();
        private int m_position = 0;

        /// <summary>
        /// Add and element to the collection
        /// </summary>
        /// <param name="element">Element to add</param>
        public void Add(IElement element)
        {
            m_collection.Add(element);
        }
        /// <summary>
        /// Number of elements in the collection
        /// </summary>
        public int Count
        {
            get { return m_collection.Count; }
        }

        /// <summary>
        /// Next element in the list
        /// </summary>
        /// <returns>Next Elment in the list</returns>
        public IElement Next()
        {
            m_position = m_position + 1;
            if (m_position < m_collection.Count)
                return (IElement)m_collection[m_position];
            else
                return null;
        }

        /// <summary>
        /// Clear the collection
        /// </summary>
        public void Clear()
        {
            m_collection.Clear();
            m_collection = null;
        }

        /// <summary>
        /// Reset the position to 0
        /// </summary>
        public void Reset()
        {
            m_position = 0;
        }
    }

Outcomes