Exemplo n.º 1
0
        public virtual void DrawItemImage(IListControl parent, ListControlDrawItemEventArgs e)
        {
            if (e.Image == null)
            {
                return;
            }
            Size size = e.Image.Size;

            e.Graphics.DrawImage(e.Image, e.Bounds.Left + e.Offset, e.Bounds.Top + (e.Bounds.Height - size.Height) / 2,
                                 size.Width, size.Height);
            e.Offset += size.Width + parent.Padding.Left;
        }
Exemplo n.º 2
0
 public virtual void DrawItemBackground(IListControl parent, ListControlDrawItemEventArgs e)
 {
     using (
         Brush brush =
             new SolidBrush(!EnumExtensions.HasFlag(e.State, DrawItemState.HotLight) ||
                            EnumExtensions.HasFlag(e.State, DrawItemState.Selected) || !AllowHotTrack
                 ? (!parent.Enabled || EnumExtensions.HasFlag(e.State, DrawItemState.Selected)
                     ? (!parent.Enabled ||
                        !parent.IsDroppedDown && parent.HideSelection &&
                        (!EnumExtensions.HasFlag(e.State, DrawItemState.Focus) && parent.FullRowSelect)
                         ? SystemColors.Control
                         : parent.HighlightBackColor)
                     : parent.BackColor)
                 : parent.HotTrackColor))
         e.Graphics.FillRectangle(brush, e.Bounds);
 }
Exemplo n.º 3
0
        public virtual void DrawItemText(IListControl parent, ListControlDrawItemEventArgs e)
        {
            int             num       = Math.Max(2, parent.Padding.Right);
            int             width     = e.Bounds.Width - (e.Offset + num);
            TextFormatFlags flags     = GetFlags(parent, e.Item.Text);
            var             rectangle = new Rectangle(e.Bounds.X + e.Offset, e.Bounds.Y,
                                                      TextRenderer.MeasureText(e.Graphics, e.Item.Text, e.Font, new Size(width, e.Bounds.Height)).Width + num,
                                                      e.Bounds.Height);

            if (rectangle.Width > width)
            {
                rectangle.Width = width;
            }
            Color foreColor;

            if (EnumExtensions.HasFlag(e.State, DrawItemState.Selected))
            {
                Color color;
                if (!parent.IsDroppedDown && parent.HideSelection &&
                    !EnumExtensions.HasFlag(e.State, DrawItemState.Focus))
                {
                    color     = SystemColors.Control;
                    foreColor = parent.ForeColor;
                }
                else
                {
                    color     = parent.HighlightBackColor;
                    foreColor = parent.HighlightForeColor;
                }
                if (!parent.FullRowSelect)
                {
                    using (Brush brush = new SolidBrush(color))
                        e.Graphics.FillRectangle(brush, rectangle);
                }
            }
            else
            {
                foreColor = parent.Enabled ? parent.ForeColor : SystemColors.GrayText;
            }
            TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Font, rectangle, foreColor, flags);
            if (!EnumExtensions.HasFlag(e.State, DrawItemState.Focus) ||
                EnumExtensions.HasFlag(e.State, DrawItemState.NoFocusRect))
            {
                return;
            }
            ControlPaint.DrawFocusRectangle(e.Graphics, parent.FullRowSelect ? e.Bounds : rectangle);
        }
Exemplo n.º 4
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            IListControlRenderer renderer       = GetRenderer();
            ImageComboItem       imageComboItem = e.Index >= 0
                ? (Items[e.Index] is ImageComboItem
                    ? (ImageComboItem)Items[e.Index]
                    : new ImageComboItem(Items[e.Index].ToString()))
                : new ImageComboItem(Text);
            var e1 = new ListControlDrawItemEventArgs(e, imageComboItem)
            {
                Image  = GetItemImage(imageComboItem),
                Offset = Padding.Left
            };

            renderer.DrawItemBackground(this, e1);
            renderer.DrawItemImage(this, e1);
            renderer.DrawItemText(this, e1);
        }
Exemplo n.º 5
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            IListControlRenderer renderer       = GetRenderer();
            ImageComboItem       imageComboItem = GetItem(e.Index);
            var e1 = new ListControlDrawItemEventArgs(e, imageComboItem)
            {
                Image  = GetItemImage(imageComboItem),
                Offset = Padding.Left
            };

            if (HoverIndex == e.Index)
            {
                e1.State |= DrawItemState.HotLight;
            }
            renderer.DrawItemBackground(this, e1);
            renderer.DrawItemImage(this, e1);
            renderer.DrawItemText(this, e1);
        }