Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        private void OnDraw(Graphics g)
        {
            // Background
            using (var brush = new SolidBrush(BackColor))
            {
                g.FillRectangle(brush, ClientRectangle);
            }

            // Element
            var rect = ClientRectangle;

            if (borderTop || borderBottom || borderLeft || borderRight)
            {
                rect.Inflate(-1, -1);
            }

            var context = new TemplateDrawContext
            {
                PreferBaseForeColor   = false,
                PreferBaseBackColor   = false,
                PreferBaseBorderColor = false,
                BaseForeColor         = ForeColor,
                BaseBackColor         = BackColor,
                BaseBorderColor       = ElementBorderColor,
                Font = Font
            };

            var designMode = (Site != null) && Site.DesignMode;
            var source     = designData as ITemplateDesignData;
            var target     = designMode & source != null?source.Create() : item;

            TemplateDrawHelper.DrawElements(g, rect, target, elements, context);

            // Border
            g.DrawBorder(borderColor, ClientRectangle, borderTop, borderBottom, borderLeft, borderRight);
        }
        //--------------------------------------------------------------------------------
        // Draw
        //--------------------------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        protected override void OnDraw(Graphics g)
        {
            // Elements
            var rect = CalcListRect();

            g.Clip = new Region(rect);

            var context = new TemplateDrawContext
            {
                BaseBorderColor = SplitterColor,
                Font            = Font
            };

            var designMode = (Site != null) && Site.DesignMode;
            var baseY      = rect.Top;
            var source     = designData as ITemplateListDesignData;
            var list       = designMode && source != null ? (IList)source.Create() : items;
            var i          = designMode ? 0 : TopIndex;
            var max        = designMode && list != null ? list.Count : items.Count;

            if (list != null)
            {
                while ((baseY < rect.Bottom) && (i < max))
                {
                    var elementRect = new Rectangle(rect.Left, baseY, rect.Width, itemHeight);
                    var selected    = i == selectedIndex;
                    var foreColor   = selected
                        ? (Focused ? selectedForeColor : inactiveSelectedForeColor)
                        : ForeColor;
                    var backColor = selected
                        ? (Focused ? selectedBackColor : inactiveSelectedBackColor)
                        : (i % 2 == 0) ? BackColor : alternateBackColor;

                    using (var brush = new SolidBrush(backColor))
                    {
                        g.FillRectangle(brush, elementRect);
                    }

                    context.PreferBaseForeColor   = selected && PreferForeColorWhenSelected;
                    context.PreferBaseBackColor   = selected && PreferBackColorWhenSelected;
                    context.PreferBaseBorderColor = selected && PreferBorderColorWhenSelected;
                    context.BaseForeColor         = foreColor;
                    context.BaseBackColor         = backColor;

                    TemplateDrawHelper.DrawElements(g, elementRect, list[i], elements, context);

                    baseY += itemHeight;

                    if (splitter)
                    {
                        using (var brush = new SolidBrush(SplitterColor))
                        {
                            g.FillRectangle(brush, new Rectangle(rect.Left, baseY, rect.Width, 1));
                        }

                        baseY += 1;
                    }

                    i++;
                }
            }

            using (var brush = new SolidBrush(BackColor))
            {
                g.FillRectangle(brush, rect.X, baseY, rect.Width, rect.Bottom - baseY);
            }

            // Border
            g.Clip = new Region(ClientRectangle);

            using (var pen = new Pen(borderColor))
            {
                g.DrawRectangle(pen, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
            }
        }