Exemplo n.º 1
0
        public void Draw(ListViewItem item, Graphics g, Rectangle rect)
        {
            if (!myOffsetsAreCorrect)
            {
                UpdateOffsets(g);
            }

            int startOffset = CalculateOffset(item);

            for (int i = 0; i < myPainters.Length; i++)
            {
                IItemPainter painter = myPainters[i];

                Size size      = painter.GetSize(item, g);
                int  offset    = myOffsets[i] + startOffset;
                int  endOffset = i == myPainters.Length - 1 ? rect.Width : myOffsets[i + 1];

                switch (myAlignments[i])
                {
                case ColumnAlignment.Right:
                    offset += (endOffset - offset) - size.Width;
                    break;

                case ColumnAlignment.Center:
                    offset += ((endOffset - offset) - size.Width) / 2;
                    break;
                }

                painter.Draw(item, g, new Rectangle(offset, 0, endOffset - offset, 0));
            }
        }
Exemplo n.º 2
0
        private void UpdateOffsets(Graphics g)
        {
            myOffsets = new int[myPainters.Length];

            int offset = 0;

            for (int i = 0; i < myPainters.Length; i++)
            {
                IItemPainter painter = myPainters[i];

                myOffsets[i] = offset;
                int maxWidth = 0;

                foreach (ListViewItem item in myItems)
                {
                    Size size = painter.GetSize(item, g);

                    if (size.Width > maxWidth)
                    {
                        maxWidth = size.Width;
                    }
                }

                offset += maxWidth + SPACING;
            }

            myWidth             = offset;
            myOffsetsAreCorrect = true;
        }
 public int CompareTo(IItemPainter other)
 {
     return(string.CompareOrdinal(Name, other.Name));
 }