GetSubItemText() public method

Returns the sub item item text corresponding to the specified column type.
public GetSubItemText ( ColumnType type ) : string
type ColumnType The type of information to return.
return string
Esempio n. 1
0
 public ImageListViewSubItem this[ColumnType type]
 {
     get
     {
         return(new ImageListViewSubItem(mParent, mParent.GetSubItemText(type)));
     }
 }
Esempio n. 2
0
        private void SetUIChanges()
        {
            this.Text                  = HormigasForm.RM.GetString("NEW_FORMAT");
            labelFileName.Text         = HormigasForm.RM.GetString("FILE_NAME");
            labelTag.Text              = HormigasForm.RM.GetString("FORMAT_TAG");
            labelYear.Text             = HormigasForm.RM.GetString("YEAR");
            labelMonth.Text            = HormigasForm.RM.GetString("MONTH");
            labelDay.Text              = HormigasForm.RM.GetString("DAY");
            labelTime.Text             = HormigasForm.RM.GetString("TIME");
            checkBoxDefaultFormat.Text = HormigasForm.RM.GetString("MAKE_DEFAULT");

            labelYearItem.Text  = "";
            labelMonthItem.Text = "";
            labelDayItem.Text   = "";
            labelTimeItem.Text  = "";

            if (m_item == null)
            {
                labelFileNameItem.Text = HormigasForm.RM.GetString("EXAMPLE_FILENAME");
                m_extension            = Path.GetExtension(labelFileNameItem.Text);
                if (m_extension.Length > 0)
                {
                    labelFileNameItem.Text = labelFileNameItem.Text.Replace(m_extension, "");
                }
                labelTagItem.Text   = HormigasForm.RM.GetString("EXAMPLE_TAG");
                labelYearItem.Text  = HormigasForm.RM.GetString("EXAMPLE_YEAR");
                labelMonthItem.Text = HormigasForm.RM.GetString("EXAMPLE_MONTH");
                labelDayItem.Text   = HormigasForm.RM.GetString("EXAMPLE_DAY");
                labelTimeItem.Text  = HormigasForm.RM.GetString("EXAMPLE_TIME");
            }
            else
            {
                labelFileNameItem.Text = m_item.Text;
                m_extension            = Path.GetExtension(m_item.Text);
                if (m_extension.Length > 0)
                {
                    labelFileNameItem.Text = labelFileNameItem.Text.Replace(m_extension, "");
                }
                labelTagItem.Text = m_item.GetSubItemText(1);
                DateTime dt = DateTime.Now;
                if (m_hf.getDateToCompare(m_item, ref dt))
                {
                    labelYearItem.Text  = dt.Year.ToString();
                    labelMonthItem.Text = dt.Month.ToString("D2");
                    labelDayItem.Text   = dt.Day.ToString("D2");
                    labelTimeItem.Text  = dt.Hour.ToString("D2") +
                                          dt.Minute.ToString("D2") +
                                          dt.Second.ToString("D2") +
                                          dt.Millisecond.ToString("D3");
                }
            }
        }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                // Fill with item background color
                if (item.BackColor != Color.Transparent)
                {
                    using (Brush brush = new SolidBrush(item.BackColor))
                    {
                        g.FillRectangle(brush, bounds);
                    }
                }

                if (ImageListView.View == View.Details)
                {
                    // Item background
                    if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                            Color.FromArgb(64, 96, 160), Color.FromArgb(64, 64, 96, 160), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }
                    else if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                            Color.FromArgb(64, Color.White), Color.FromArgb(16, Color.White), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }

                    // Shade sort column
                    List<ImageListView.ImageListViewColumnHeader> uicolumns = mImageListView.Columns.GetDisplayedColumns();
                    int x = mImageListView.layoutManager.ColumnHeaderBounds.Left;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        if (mImageListView.SortColumn == column.Type && mImageListView.SortOrder != SortOrder.None &&
                            (state & ItemState.Hovered) == ItemState.None && (state & ItemState.Selected) == ItemState.None)
                        {
                            Rectangle subItemBounds = bounds;
                            subItemBounds.X = x;
                            subItemBounds.Width = column.Width;
                            using (Brush brush = new SolidBrush(Color.FromArgb(32, 128, 128, 128)))
                            {
                                g.FillRectangle(brush, subItemBounds);
                            }
                            break;
                        }
                        x += column.Width;
                    }
                    // Separators
                    x = mImageListView.layoutManager.ColumnHeaderBounds.Left;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        x += column.Width;
                        if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                        {
                            using (Pen pen = new Pen(Color.FromArgb(64, 128, 128, 128)))
                            {
                                g.DrawLine(pen, x, bounds.Top, x, bounds.Bottom);
                            }
                        }
                    }

                    // Item texts
                    Size offset = new Size(2, (bounds.Height - mImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.Alignment = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        // Sub text
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            using (Brush bItemFore = new SolidBrush(Color.White))
                            {
                                g.DrawString(item.GetSubItemText(column.Type), mImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.X += column.Width;
                        }
                    }

                    // Border
                    if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(128, Color.White)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(96, 144, 240)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                }
                else
                {
                    // Align images to bottom of bounds
                    Image img = item.ThumbnailImage;
                    Rectangle pos = Utility.GetSizedImageBounds(img,
                        new Rectangle(bounds.X + padding, bounds.Y + padding, bounds.Width - 2 * padding, bounds.Height - 2 * padding - mReflectionSize),
                        50.0f, 100.0f);

                    int x = pos.X;
                    int y = pos.Y;

                    // Item background
                    if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(
                            new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                            Color.FromArgb(64, 96, 160), Color.FromArgb(16, 16, 16)))
                        {
                            g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                        }
                    }
                    else if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(
                            new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                            Color.FromArgb(64, Color.White), Color.FromArgb(16, 16, 16)))
                        {
                            g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                        }
                    }

                    // Border
                    if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(
                            new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                            Color.FromArgb(128, Color.White), Color.FromArgb(16, 16, 16)))
                        using (Pen pen = new Pen(brush))
                        {
                            g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(
                            new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                            Color.FromArgb(96, 144, 240), Color.FromArgb(16, 16, 16)))
                        using (Pen pen = new Pen(brush))
                        {
                            g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                        }
                    }

                    // Draw item image
                    DrawImageWithReflection(g, img, pos, mReflectionSize);

                    // Highlight
                    using (Pen pen = new Pen(Color.FromArgb(160, Color.White)))
                    {
                        g.DrawLine(pen, pos.X, pos.Y + 1, pos.X + pos.Width - 1, pos.Y + 1);
                        g.DrawLine(pen, pos.X, pos.Y + 1, pos.X, pos.Y + pos.Height);
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    // Zoom on mouse over
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        bounds.Inflate((int)(bounds.Width * mZoomRatio), (int)(bounds.Height * mZoomRatio));
                        if (bounds.Bottom > ItemAreaBounds.Bottom)
                            bounds.Y = ItemAreaBounds.Bottom - bounds.Height;
                        if (bounds.Top < ItemAreaBounds.Top)
                            bounds.Y = ItemAreaBounds.Top;
                        if (bounds.Right > ItemAreaBounds.Right)
                            bounds.X = ItemAreaBounds.Right - bounds.Width;
                        if (bounds.Left < ItemAreaBounds.Left)
                            bounds.X = ItemAreaBounds.Left;
                    }

                    // Get item image
                    Image img = null;
                    if ((state & ItemState.Hovered) != ItemState.None)
                        img = GetImageAsync(item, new Size(bounds.Width - 8, bounds.Height - 8));
                    if (img == null) img = item.ThumbnailImage;

                    // Calculate image bounds
                    Rectangle pos = Utility.GetSizedImageBounds(img, Rectangle.Inflate(bounds, -4, -4));
                    int imageWidth = pos.Width;
                    int imageHeight = pos.Height;
                    int imageX = pos.X;
                    int imageY = pos.Y;

                    // Allocate space for item text
                    if ((state & ItemState.Hovered) != ItemState.None &&
                        (bounds.Height - imageHeight) / 2 < ImageListView.Font.Height + 8)
                    {
                        int delta = (ImageListView.Font.Height + 8) - (bounds.Height - imageHeight) / 2;
                        bounds.Height += 2 * delta;
                        imageY += delta;
                    }

                    // Paint background
                    using (Brush bBack = new SolidBrush(ImageListView.BackColor))
                    {
                        Utility.FillRoundedRectangle(g, bBack, bounds, 5);
                    }
                    using (Brush bItemBack = new SolidBrush(item.BackColor))
                    {
                        Utility.FillRoundedRectangle(g, bItemBack, bounds, 5);
                    }
                    if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 5);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 5);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 5);
                        }
                    }

                    // Draw the image
                    g.DrawImage(img, imageX, imageY, imageWidth, imageHeight);

                    // Draw image border
                    if (Math.Min(imageWidth, imageHeight) > 32)
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, Color.Gray)))
                        {
                            g.DrawRectangle(pGray128, imageX, imageY, imageWidth, imageHeight);
                        }
                        if (System.Math.Min(imageWidth, imageHeight) > 32)
                        {
                            using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                            {
                                g.DrawRectangle(pWhite128, imageX + 1, imageY + 1, imageWidth - 2, imageHeight - 2);
                            }
                        }
                    }

                    // Draw item text
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt = new RectangleF(bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, (bounds.Height - imageHeight) / 2 - 8);
                            sf.Alignment = StringAlignment.Center;
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming = StringTrimming.EllipsisCharacter;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, ImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.Y = bounds.Bottom - (bounds.Height - imageHeight) / 2 + 4;
                            string details = "";
                            if (item.Dimensions != Size.Empty)
                                details += item.GetSubItemText(ColumnType.Dimensions) + " pixels ";
                            if (item.FileSize != 0)
                                details += item.GetSubItemText(ColumnType.FileSize);
                            using (Brush bGrayText = new SolidBrush(Color.Gray))
                            {
                                g.DrawString(details, ImageListView.Font, bGrayText, rt, sf);
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                Clip = (ImageListView.View == Manina.Windows.Forms.View.Details);

                if (ImageListView.View != Manina.Windows.Forms.View.Details)
                {
                    Rectangle controlBounds = ClientBounds;

                    // Zoom on mouse over
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        bounds.Inflate((int)(bounds.Width * mZoomRatio), (int)(bounds.Height * mZoomRatio));
                        if (bounds.Bottom > controlBounds.Bottom)
                            bounds.Y = controlBounds.Bottom - bounds.Height;
                        if (bounds.Top < controlBounds.Top)
                            bounds.Y = controlBounds.Top;
                        if (bounds.Right > controlBounds.Right)
                            bounds.X = controlBounds.Right - bounds.Width;
                        if (bounds.Left < controlBounds.Left)
                            bounds.X = controlBounds.Left;
                    }

                    // Get item image
                    Image img = null;
                    if ((state & ItemState.Hovered) != ItemState.None)
                        img = GetImageAsync(item, new Size(bounds.Width - 8, bounds.Height - 8));
                    if (img == null) img = item.GetCachedImage(CachedImageType.Thumbnail);

                    int imageWidth = 0;
                    int imageHeight = 0;
                    if (img != null)
                    {
                        // Calculate image bounds
                        Rectangle pos = Utility.GetSizedImageBounds(img, Rectangle.Inflate(bounds, -4, -4));
                        imageWidth = pos.Width;
                        imageHeight = pos.Height;
                        int imageX = pos.X;
                        int imageY = pos.Y;

                        // Allocate space for item text
                        if ((state & ItemState.Hovered) != ItemState.None &&
                            (bounds.Height - imageHeight) / 2 < ImageListView.Font.Height + 8)
                        {
                            int delta = (ImageListView.Font.Height + 8) - (bounds.Height - imageHeight) / 2;
                            bounds.Height += 2 * delta;
                            imageY += delta;

                            delta = 0;
                            if (bounds.Bottom > controlBounds.Bottom)
                                delta = bounds.Y - (controlBounds.Bottom - bounds.Height);
                            if (bounds.Top < controlBounds.Top)
                                delta = bounds.Y - controlBounds.Top;

                            bounds.Y -= delta;
                            imageY -= delta;
                        }

                        // Paint background
                        if (ImageListView.Enabled)
                        {
                            using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
                            {
                                g.FillRectangle(bItemBack, bounds);
                            }
                        }
                        else
                        {
                            using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
                            {
                                g.FillRectangle(bItemBack, bounds);
                            }
                        }

                        if ((state & ItemState.Disabled) != ItemState.None)
                        {
                            using (Brush bDisabled = new LinearGradientBrush(bounds, ImageListView.Colors.DisabledColor1, ImageListView.Colors.DisabledColor2, LinearGradientMode.Vertical))
                            {
                                Utility.FillRoundedRectangle(g, bDisabled, bounds, 5);
                            }
                        }
                        else if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                            (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                        {
                            using (Brush bSelected = new LinearGradientBrush(bounds, ImageListView.Colors.SelectedColor1, ImageListView.Colors.SelectedColor2, LinearGradientMode.Vertical))
                            {
                                Utility.FillRoundedRectangle(g, bSelected, bounds, 5);
                            }
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Brush bGray64 = new LinearGradientBrush(bounds, ImageListView.Colors.UnFocusedColor1, ImageListView.Colors.UnFocusedColor2, LinearGradientMode.Vertical))
                            {
                                Utility.FillRoundedRectangle(g, bGray64, bounds, 5);
                            }
                        }
                        if (((state & ItemState.Hovered) != ItemState.None))
                        {
                            using (Brush bHovered = new LinearGradientBrush(bounds, ImageListView.Colors.HoverColor1, ImageListView.Colors.HoverColor2, LinearGradientMode.Vertical))
                            {
                                Utility.FillRoundedRectangle(g, bHovered, bounds, 5);
                            }
                        }

                        // Draw the image
                        g.DrawImage(img, imageX, imageY, imageWidth, imageHeight);

                        // Draw image border
                        if (Math.Min(imageWidth, imageHeight) > 32)
                        {
                            using (Pen pOuterBorder = new Pen(ImageListView.Colors.ImageOuterBorderColor))
                            {
                                g.DrawRectangle(pOuterBorder, imageX, imageY, imageWidth, imageHeight);
                            }
                            if (System.Math.Min(imageWidth, imageHeight) > 32)
                            {
                                using (Pen pInnerBorder = new Pen(ImageListView.Colors.ImageInnerBorderColor))
                                {
                                    g.DrawRectangle(pInnerBorder, imageX + 1, imageY + 1, imageWidth - 2, imageHeight - 2);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Paint background
                        if (ImageListView.Enabled)
                        {
                            using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
                            {
                                g.FillRectangle(bItemBack, bounds);
                            }
                        }
                        else
                        {
                            using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
                            {
                                g.FillRectangle(bItemBack, bounds);
                            }
                        }
                    }

                    // Draw item text
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt = new RectangleF(bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, (bounds.Height - imageHeight) / 2 - 8);
                            sf.Alignment = StringAlignment.Center;
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming = StringTrimming.EllipsisCharacter;
                            using (Brush bItemFore = new SolidBrush(ImageListView.Colors.ForeColor))
                            {
                                g.DrawString(item.Text, ImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.Y = bounds.Bottom - (bounds.Height - imageHeight) / 2 + 4;
                            string details = "";
                            string dimensions = item.GetSubItemText(ColumnType.Dimensions);
                            if (!string.IsNullOrEmpty(dimensions))
                                details += dimensions + " pixels ";
                            string fileSize = item.GetSubItemText(ColumnType.FileSize);
                            if (!string.IsNullOrEmpty(fileSize))
                                details += item.GetSubItemText(ColumnType.FileSize);
                            using (Brush bGrayText = new SolidBrush(ImageListView.Colors.PaneLabelColor))
                            {
                                g.DrawString(details, ImageListView.Font, bGrayText, rt, sf);
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, ImageListView.Colors.ControlBackColor)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (((state & ItemState.Disabled) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(ImageListView.Colors.DisabledBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(ImageListView.Colors.SelectedBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(ImageListView.Colors.UnFocusedBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(ImageListView.Colors.BorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(ImageListView.Colors.HoverBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
            /// <summary>
            /// Draws the left pane in Pane view mode.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="image">The image to draw.</param>
            /// <param name="bounds">The bounding rectangle of the pane.</param>
            public override void DrawPane(Graphics g, ImageListViewItem item, Image image, Rectangle bounds)
            {
                // Draw pane background
                if (ImageListView.Enabled)
                    g.FillRectangle(SystemBrushes.Window, bounds);
                else
                    g.FillRectangle(SystemBrushes.Control, bounds);

                using (Brush bBorder = new SolidBrush(Color.FromArgb(128, SystemColors.GrayText)))
                {
                    g.FillRectangle(bBorder, bounds.Right - 2, bounds.Top, 2, bounds.Height);
                }
                bounds.Width -= 2;

                if (item != null && image != null)
                {
                    // Calculate image bounds
                    Size itemMargin = MeasureItemMargin(ImageListView.View);
                    Rectangle pos = Utility.GetSizedImageBounds(image, new Rectangle(bounds.Location + itemMargin, bounds.Size - itemMargin - itemMargin), 50.0f, 0.0f);
                    // Draw image
                    g.DrawImage(image, pos);
                    // Draw image border
                    if (Math.Min(pos.Width, pos.Height) > 32)
                    {
                        using (Pen pBorder = new Pen(SystemColors.WindowText))
                        {
                            g.DrawRectangle(pBorder, pos);
                        }
                    }
                    bounds.X += itemMargin.Width;
                    bounds.Width -= 2 * itemMargin.Width;
                    bounds.Y = pos.Height + 16;
                    bounds.Height -= pos.Height + 16;

                    // Item text
                    if (ImageListView.Columns.HasType(ColumnType.Name) && ImageListView.Columns[ColumnType.Name].Visible && bounds.Height > 0)
                    {
                        string text = item.GetSubItemText(ColumnType.Name);
                        int y = Utility.DrawStringPair(g, bounds, "", text, ImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
                        bounds.Y += 2 * y;
                        bounds.Height -= 2 * y;
                    }

                    // File type
                    string fileType = item.GetSubItemText(ColumnType.FileType);
                    if (ImageListView.Columns.HasType(ColumnType.FileType) && ImageListView.Columns[ColumnType.FileType].Visible && bounds.Height > 0 && !string.IsNullOrEmpty(fileType))
                    {
                        int y = Utility.DrawStringPair(g, bounds, ImageListView.Columns[ColumnType.FileType].Text + ": ",
                            fileType, ImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
                        bounds.Y += y;
                        bounds.Height -= y;
                    }

                    // Metatada
                    foreach (ImageListView.ImageListViewColumnHeader column in ImageListView.Columns)
                    {
                        if (column.Type == ColumnType.ImageDescription)
                        {
                            bounds.Y += 8;
                            bounds.Height -= 8;
                        }

                        if (bounds.Height <= 0) break;

                        if (column.Visible &&
                            column.Type != ColumnType.Custom &&
                            column.Type != ColumnType.FileType &&
                            column.Type != ColumnType.DateAccessed &&
                            column.Type != ColumnType.FileName &&
                            column.Type != ColumnType.FilePath &&
                            column.Type != ColumnType.Name)
                        {
                            string caption = column.Text;
                            string text = item.GetSubItemText(column.Type);
                            if (!string.IsNullOrEmpty(text))
                            {
                                int y = Utility.DrawStringPair(g, bounds, caption + ": ", text,
                                    ImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
                                bounds.Y += y;
                                bounds.Height -= y;
                            }
                        }
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(System.Drawing.Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
            {
                // Paint background
                if (ImageListView.Enabled || !item.Enabled)
                    g.FillRectangle(SystemBrushes.Window, bounds);
                else
                    g.FillRectangle(SystemBrushes.Control, bounds);

                if (ImageListView.View != Manina.Windows.Forms.View.Details)
                {
                    Size itemPadding = new Size(4, 4);

                    // Draw the image
                    Image img = item.GetCachedImage(CachedImageType.Thumbnail);
                    if (img != null)
                    {
                        Rectangle border = new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize);
                        Rectangle pos = Utility.GetSizedImageBounds(img, border);
                        g.DrawImage(img, pos);

                        // Draw image border
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.Highlight, 3))
                            {
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.GrayText, 3))
                            {
                                pen.Alignment = PenAlignment.Center;
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                            {
                                g.DrawRectangle(pGray128, border);
                            }
                        }
                    }

                    // Draw item text
                    SizeF szt = TextRenderer.MeasureText(g, item.Text, ImageListView.Font);
                    RectangleF rt;
                    using (StringFormat sf = new StringFormat())
                    {
                        rt = new RectangleF(bounds.Left + itemPadding.Width, bounds.Top + 3 * itemPadding.Height + ImageListView.ThumbnailSize.Height, ImageListView.ThumbnailSize.Width, szt.Height);
                        sf.Alignment = StringAlignment.Center;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        rt.Width += 1;
                        rt.Inflate(1, 2);
                        if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                            rt.Inflate(-1, -1);
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.Highlight, rt);
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.GrayText, rt);
                        }
                        if ((state & ItemState.Disabled) != ItemState.None)
                        {
                            g.DrawString(item.Text, ImageListView.Font, SystemBrushes.GrayText, rt, sf);
                        }
                        else if (((state & ItemState.Selected) != ItemState.None))
                        {
                            g.DrawString(item.Text, ImageListView.Font, SystemBrushes.HighlightText, rt, sf);
                        }
                        else
                        {
                            g.DrawString(item.Text, ImageListView.Font, SystemBrushes.WindowText, rt, sf);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        Rectangle fRect = Rectangle.Round(rt);
                        fRect.Inflate(1, 1);
                        ControlPaint.DrawFocusRectangle(g, fRect);
                    }
                }
                else // if (ImageListView.View == Manina.Windows.Forms.View.Details)
                {
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.Highlight, bounds);
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.GrayText, bounds);
                    }

                    Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.Alignment = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        // Sub text
                        List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            int iconOffset = 0;
                            if (column.Type == ColumnType.Name)
                            {
                                // Allocate space for checkbox and file icon
                                if (ImageListView.ShowCheckBoxes && ImageListView.ShowFileIcons)
                                    iconOffset += 2 * 16 + 3 * 2;
                                else if (ImageListView.ShowCheckBoxes)
                                    iconOffset += 16 + 2 * 2;
                                else if (ImageListView.ShowFileIcons)
                                    iconOffset += 16 + 2 * 2;
                            }
                            rt.X += iconOffset;
                            rt.Width -= iconOffset;

                            Brush forecolor = SystemBrushes.WindowText;
                            if ((state & ItemState.Disabled) != ItemState.None)
                                forecolor = SystemBrushes.GrayText;
                            else if ((state & ItemState.Selected) != ItemState.None)
                                forecolor = SystemBrushes.HighlightText;

                            if (column.Type == ColumnType.Rating && ImageListView.RatingImage != null && ImageListView.EmptyRatingImage != null)
                            {
                                int w = ImageListView.RatingImage.Width;
                                int y = (int)(rt.Top + (rt.Height - ImageListView.RatingImage.Height) / 2.0f);
                                int rating = item.StarRating;
                                if (rating < 0) rating = 0;
                                if (rating > 5) rating = 5;
                                for (int i = 1; i <= rating; i++)
                                    g.DrawImage(ImageListView.RatingImage, rt.Left + (i - 1) * w, y);
                                for (int i = rating + 1; i <= 5; i++)
                                    g.DrawImage(ImageListView.EmptyRatingImage, rt.Left + (i - 1) * w, y);
                            }
                            else if (column.Type == ColumnType.Custom)
                                g.DrawString(item.GetSubItemText(column.Guid), ImageListView.Font, forecolor, rt, sf);
                            else
                                g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, forecolor, rt, sf);

                            rt.X -= iconOffset;
                            rt.X += column.Width;
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                        ControlPaint.DrawFocusRectangle(g, bounds);
                }
            }
Esempio n. 8
0
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(System.Drawing.Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
            {
                // Paint background
                using (Brush bItemBack = new SolidBrush(item.BackColor))
                {
                    g.FillRectangle(bItemBack, bounds);
                }

                if (ImageListView.View != Manina.Windows.Forms.View.Details)
                {
                    Size itemPadding = new Size(4, 4);

                    // Draw the image
                    Image img = item.ThumbnailImage;
                    if (img != null)
                    {
                        Rectangle border = new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize);
                        Rectangle pos    = Utility.GetSizedImageBounds(img, border);

                        //g.DrawImage(img, pos);
                        DrawThumbnail(g, item, img, pos);

                        // Draw image border
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.Highlight, 3))
                            {
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.GrayText, 3))
                            {
                                pen.Alignment = PenAlignment.Center;
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                            {
                                g.DrawRectangle(pGray128, border);
                            }
                        }
                    }

                    // Draw item text
                    SizeF      szt = TextRenderer.MeasureText(item.Text, ImageListView.Font);
                    RectangleF rt;
                    using (StringFormat sf = new StringFormat())
                    {
                        rt               = new RectangleF(bounds.Left + itemPadding.Width, bounds.Top + 3 * itemPadding.Height + ImageListView.ThumbnailSize.Height, ImageListView.ThumbnailSize.Width, szt.Height);
                        sf.Alignment     = StringAlignment.Center;
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        rt.Width        += 1;
                        rt.Inflate(1, 2);
                        if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                        {
                            rt.Inflate(-1, -1);
                        }
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.Highlight, rt);
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.GrayText, rt);
                        }
                        if (((state & ItemState.Selected) != ItemState.None))
                        {
                            g.DrawString(item.Text, ImageListView.Font, SystemBrushes.HighlightText, rt, sf);
                        }
                        else
                        {
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, ImageListView.Font, bItemFore, rt, sf);
                            }
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        Rectangle fRect = Rectangle.Round(rt);
                        fRect.Inflate(1, 1);
                        ControlPaint.DrawFocusRectangle(g, fRect);
                    }
                }
                else
                {
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.Highlight, bounds);
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.GrayText, bounds);
                    }

                    Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.Alignment     = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        // Sub text
                        List <ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                if ((state & ItemState.Selected) == ItemState.None)
                                {
                                    g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, bItemFore, rt, sf);
                                }
                                else
                                {
                                    g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, SystemBrushes.HighlightText, rt, sf);
                                }
                            }
                            rt.X += column.Width;
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        ControlPaint.DrawFocusRectangle(g, bounds);
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(System.Drawing.Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
            {
                // Paint background
                using (Brush bItemBack = new SolidBrush(item.BackColor))
                {
                    g.FillRectangle(bItemBack, bounds);
                }

                if (ImageListView.View != Manina.Windows.Forms.View.Details)
                {
                    Size itemPadding = new Size(4, 4);

                    // Draw the image
                    Image img = item.ThumbnailImage;
                    if (img != null)
                    {
                        Rectangle border = new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize);
                        Rectangle pos = Utility.GetSizedImageBounds(img, border);
                        g.DrawImage(img, pos);

                        // Draw image border
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.Highlight, 3))
                            {
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            using (Pen pen = new Pen(SystemColors.GrayText, 3))
                            {
                                pen.Alignment = PenAlignment.Center;
                                g.DrawRectangle(pen, border);
                            }
                        }
                        else
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                            {
                                g.DrawRectangle(pGray128, border);
                            }
                        }
                    }

                    // Draw item text
                    SizeF szt = TextRenderer.MeasureText(item.Text, ImageListView.Font);
                    RectangleF rt;
                    using (StringFormat sf = new StringFormat())
                    {
                        rt = new RectangleF(bounds.Left + itemPadding.Width, bounds.Top + 3 * itemPadding.Height + ImageListView.ThumbnailSize.Height, ImageListView.ThumbnailSize.Width, szt.Height);
                        sf.Alignment = StringAlignment.Center;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        rt.Width += 1;
                        rt.Inflate(1, 2);
                        if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                            rt.Inflate(-1, -1);
                        if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.Highlight, rt);
                        }
                        else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                        {
                            g.FillRectangle(SystemBrushes.GrayText, rt);
                        }
                        if (((state & ItemState.Selected) != ItemState.None))
                        {
                            g.DrawString(item.Text, ImageListView.Font, SystemBrushes.HighlightText, rt, sf);
                        }
                        else
                        {
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, ImageListView.Font, bItemFore, rt, sf);
                            }
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        Rectangle fRect = Rectangle.Round(rt);
                        fRect.Inflate(1, 1);
                        ControlPaint.DrawFocusRectangle(g, fRect);
                    }
                }
                else
                {
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.Highlight, bounds);
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        g.FillRectangle(SystemBrushes.GrayText, bounds);
                    }

                    Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.Alignment = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        // Sub text
                        List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                if ((state & ItemState.Selected) == ItemState.None)
                                    g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, bItemFore, rt, sf);
                                else
                                    g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, SystemBrushes.HighlightText, rt, sf);
                            }
                            rt.X += column.Width;
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                        ControlPaint.DrawFocusRectangle(g, bounds);
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                VisualStyleRenderer rBack;

                if (!ImageListView.Enabled)
                    rBack = rItemSelectedHidden;
                if (((state & ItemState.Disabled) != ItemState.None))
                    rBack = rItemDisabled;
                else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    rBack = rItemSelectedHidden;
                else if (((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None))
                    rBack = rItemHoveredSelected;
                else if ((state & ItemState.Selected) != ItemState.None)
                    rBack = rItemSelected;
                else if ((state & ItemState.Hovered) != ItemState.None)
                    rBack = rItemHovered;
                else
                    rBack = rItemNormal;

                if (VisualStylesEnabled && rBack != null)
                {
                    // Do not draw the background of normal items
                    if (((state & ItemState.Hovered) != ItemState.None) || ((state & ItemState.Selected) != ItemState.None))
                        rBack.DrawBackground(g, bounds, bounds);

                    Size itemPadding = new Size(7, 7);

                    // Draw the image
                    if (ImageListView.View != View.Details)
                    {
                        Image img = item.GetCachedImage(CachedImageType.Thumbnail);
                        if (img != null)
                        {
                            Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
                            // Image background
                            Rectangle imgback = pos;
                            imgback.Inflate(3, 3);
                            g.FillRectangle(SystemBrushes.Window, imgback);
                            // Image border
                            if (img.Width > 32 && img.Height > 32)
                            {
                                using (Pen pen = new Pen(Color.FromArgb(224, 224, 244)))
                                {
                                    g.DrawRectangle(pen, imgback.X, imgback.Y, imgback.Width - 1, imgback.Height - 1);
                                }
                            }
                            // Image
                            g.DrawImage(img, pos);
                        }

                        // Draw item text
                        Color foreColor = SystemColors.ControlText;
                        if ((state & ItemState.Disabled) != ItemState.None)
                            foreColor = SystemColors.GrayText;
                        Size szt = TextRenderer.MeasureText(item.Text, ImageListView.Font);
                        Rectangle rt = new Rectangle(
                            bounds.Left + itemPadding.Width, bounds.Top + 2 * itemPadding.Height + ImageListView.ThumbnailSize.Height,
                            ImageListView.ThumbnailSize.Width, szt.Height);
                        TextRenderer.DrawText(g, item.Text, ImageListView.Font, rt, foreColor,
                            TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);
                    }
                    else // if (ImageListView.View == View.Details)
                    {
                        List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();

                        // Separators
                        int x = bounds.Left - 2;
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            x += column.Width;
                            if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                            {
                                using (Pen pGray32 = new Pen(Color.FromArgb(32, 128, 128, 128)))
                                {
                                    g.DrawLine(pGray32, x, bounds.Top, x, bounds.Bottom);
                                }
                            }
                        }
                        Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                        // Sub text
                        int firstWidth = 0;
                        if (uicolumns.Count > 0)
                            firstWidth = uicolumns[0].Width;
                        Rectangle rt = new Rectangle(bounds.Left + offset.Width, bounds.Top + offset.Height, firstWidth - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        Color foreColor = SystemColors.ControlText;
                        if ((state & ItemState.Disabled) != ItemState.None)
                            foreColor = SystemColors.GrayText;
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            using (Brush bItemFore = new SolidBrush(SystemColors.ControlText))
                            {
                                int iconOffset = 0;
                                if (column.Type == ColumnType.Name)
                                {
                                    // Allocate space for checkbox and file icon
                                    if (ImageListView.ShowCheckBoxes && ImageListView.ShowFileIcons)
                                        iconOffset += 2 * 16 + 3 * 2;
                                    else if (ImageListView.ShowCheckBoxes)
                                        iconOffset += 16 + 2 * 2;
                                    else if (ImageListView.ShowFileIcons)
                                        iconOffset += 16 + 2 * 2;
                                }
                                rt.X += iconOffset;
                                rt.Width -= iconOffset;
                                // Rating stars
                                if (column.Type == ColumnType.Rating && ImageListView.RatingImage != null && ImageListView.EmptyRatingImage != null)
                                {
                                    int rating = item.GetSimpleRating();
                                    if (rating > 0)
                                    {
                                        int w = ImageListView.RatingImage.Width;
                                        int y = (int)(rt.Top + (rt.Height - ImageListView.RatingImage.Height) / 2.0f);

                                        for (int i = 1; i <= 5; i++)
                                        {
                                            if (rating >= i)
                                                g.DrawImage(ImageListView.RatingImage, rt.Left + (i - 1) * w, y);
                                            else
                                                g.DrawImage(ImageListView.EmptyRatingImage, rt.Left + (i - 1) * w, y);
                                        }
                                    }
                                }
                                else if (column.Type == ColumnType.Custom)
                                    TextRenderer.DrawText(g, item.GetSubItemText(column.Guid), ImageListView.Font, rt, foreColor,
                                        TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);
                                else
                                    TextRenderer.DrawText(g, item.GetSubItemText(column.Type), ImageListView.Font, rt, foreColor,
                                        TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);

                                rt.X -= iconOffset;
                            }
                            rt.X += column.Width;
                        }
                    }

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        Rectangle focusBounds = bounds;
                        focusBounds.Inflate(-2, -2);
                        ControlPaint.DrawFocusRectangle(g, focusBounds);
                    }

                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                // Item background color
                using (Brush brush = new SolidBrush(Color.Black))
                {
                    g.FillRectangle(brush, bounds);
                }

                if (ImageListView.View == View.Details)
                {
                    // Item background
                    if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                            Color.FromArgb(64, 96, 160), Color.FromArgb(64, 64, 96, 160), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }
                    else if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                            Color.FromArgb(64, Color.White), Color.FromArgb(16, Color.White), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }

                    // Shade sort column
                    List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();
                    int x = bounds.Left - 1;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        if (ImageListView.SortColumn >= 0 && ImageListView.SortColumn < ImageListView.Columns.Count &&
                            ImageListView.Columns[ImageListView.SortColumn].Guid == column.Guid &&
                            ImageListView.SortOrder != SortOrder.None &&
                            (state & ItemState.Hovered) == ItemState.None && (state & ItemState.Selected) == ItemState.None)
                        {
                            Rectangle subItemBounds = bounds;
                            subItemBounds.X = x;
                            subItemBounds.Width = column.Width;
                            using (Brush brush = new SolidBrush(Color.FromArgb(32, 128, 128, 128)))
                            {
                                g.FillRectangle(brush, subItemBounds);
                            }
                            break;
                        }
                        x += column.Width;
                    }
                    // Separators
                    x = ImageListView.layoutManager.ColumnHeaderBounds.Left;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        x += column.Width;
                        if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                        {
                            using (Pen pen = new Pen(Color.FromArgb(64, 128, 128, 128)))
                            {
                                g.DrawLine(pen, x, bounds.Top, x, bounds.Bottom);
                            }
                        }
                    }

                    // Item texts
                    Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.Alignment = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        // Sub text
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            Color foreColor = Color.White;
                            if (!item.Enabled) foreColor = Color.FromArgb(128, 128, 128);
                            using (Brush bItemFore = new SolidBrush(foreColor))
                            {
                                if (column.Type == ColumnType.Rating && ImageListView.RatingImage != null && ImageListView.EmptyRatingImage != null)
                                {
                                    string srating = item.GetSubItemText(ColumnType.Rating);
                                    if (!string.IsNullOrEmpty(srating))
                                    {
                                        int w = ImageListView.RatingImage.Width;
                                        int y = (int)(rt.Top + (rt.Height - ImageListView.RatingImage.Height) / 2.0f);
                                        int rating = item.StarRating;
                                        if (rating < 0) rating = 0;
                                        if (rating > 5) rating = 5;
                                        for (int i = 1; i <= rating; i++)
                                            g.DrawImage(ImageListView.RatingImage, rt.Left + (i - 1) * w, y);
                                        for (int i = rating + 1; i <= 5; i++)
                                            g.DrawImage(ImageListView.EmptyRatingImage, rt.Left + (i - 1) * w, y);
                                    }
                                }
                                else if (column.Type == ColumnType.Custom)
                                    g.DrawString(item.GetSubItemText(column.Guid), ImageListView.Font, bItemFore, rt, sf);
                                else
                                    g.DrawString(item.GetSubItemText(column.Type), ImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.X += column.Width;
                        }
                    }

                    // Border
                    if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(128, Color.White)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(96, 144, 240)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                }
                else // if (ImageListView.View != View.Details)
                {
                    // Align images to bottom of bounds
                    Image img = item.GetCachedImage(CachedImageType.Thumbnail);
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img,
                            new Rectangle(bounds.X + padding, bounds.Y + padding, bounds.Width - 2 * padding, bounds.Height - 2 * padding - mReflectionSize),
                            50.0f, 100.0f);

                        int x = pos.X;
                        int y = pos.Y;

                        // Item background
                        if ((state & ItemState.Selected) == ItemState.Selected)
                        {
                            using (Brush brush = new LinearGradientBrush(
                                new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                Color.FromArgb(64, 96, 160), Color.FromArgb(16, 16, 16)))
                            {
                                g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                            }
                        }
                        else if ((state & ItemState.Hovered) == ItemState.Hovered)
                        {
                            using (Brush brush = new LinearGradientBrush(
                                new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                Color.FromArgb(64, Color.White), Color.FromArgb(16, 16, 16)))
                            {
                                g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                            }
                        }

                        // Border
                        if ((state & ItemState.Hovered) == ItemState.Hovered)
                        {
                            using (Brush brush = new LinearGradientBrush(
                                new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                Color.FromArgb(128, Color.White), Color.FromArgb(16, 16, 16)))
                            using (Pen pen = new Pen(brush))
                            {
                                g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                            }
                        }
                        else if ((state & ItemState.Selected) == ItemState.Selected)
                        {
                            using (Brush brush = new LinearGradientBrush(
                                new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                Color.FromArgb(96, 144, 240), Color.FromArgb(16, 16, 16)))
                            using (Pen pen = new Pen(brush))
                            {
                                g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                            }
                        }

                        // Draw item image
                        DrawImageWithReflection(g, img, pos, mReflectionSize);

                        // Shade over disabled item image
                        if (!item.Enabled)
                        {
                            pos.Inflate(4, 4);
                            using (Brush brush = new LinearGradientBrush(pos,
                                Color.FromArgb(64, 0, 0, 0), Color.FromArgb(196, 0, 0, 0), LinearGradientMode.Vertical))
                            {
                                g.FillRectangle(brush, pos);
                            }
                        }

                        // Highlight
                        if (item.Enabled)
                        {
                            using (Pen pen = new Pen(Color.FromArgb(160, Color.White)))
                            {
                                g.DrawLine(pen, pos.X, pos.Y + 1, pos.X + pos.Width - 1, pos.Y + 1);
                                g.DrawLine(pen, pos.X, pos.Y + 1, pos.X, pos.Y + pos.Height);
                            }
                        }
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                // Do not draw the background of normal items
                if (((state & ItemState.Hovered) != ItemState.None) || ((state & ItemState.Selected) != ItemState.None))
                {
                    // g.FillRectangle(new SolidBrush(Color.Red), bounds);
                    if (this.ImageListView._palette != null)
                    {
                        // (3) Get the renderer associated with this palette
                        IRenderer renderer = this.ImageListView._palette.GetRenderer();

                        // (4) Create the rendering context that is passed into all renderer calls
                        using (RenderContext renderContext = new RenderContext(this.ImageListView, g, bounds, renderer))
                        {
                            // (5) Set style required when rendering
                            this.ImageListView._paletteBack.Style = PaletteBackStyle.ButtonStandalone;
                            this.ImageListView._paletteBorder.Style = PaletteBorderStyle.ButtonStandalone;
                            this.ImageListView._paletteContent.Style = PaletteContentStyle.ButtonStandalone;

                            if (this.ImageListView._paletteBack.GetBackDraw(PaletteState.Normal) == InheritBool.True)
                            {
                                using (GraphicsPath path = new GraphicsPath())
                                {
                                    // (8) Add entire control client area to drawing path
                                    path.AddRectangle(bounds);

                                    // (9) Perform drawing of the background clipped to the path
                                    this.ImageListView._mementoBack1 = renderer.RenderStandardBack.DrawBack(renderContext,
                                        bounds,
                                        path,
                                        this.ImageListView._paletteBack,
                                        VisualOrientation.Top,
                                    GetButtonState(state),
                                        this.ImageListView._mementoBack1);

                                }
                                renderer.RenderStandardBorder.DrawBorder(renderContext,bounds, this.ImageListView._paletteBorder, VisualOrientation.Top, PaletteState.Pressed);
                            }
                        }
                    }
                }
                Size itemPadding = new Size(4,4);

                // Draw the image
                if (ImageListView.View != View.Details)
                {
                    Image img = item.GetCachedImage(CachedImageType.Thumbnail);
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
                        // Image background
                        Rectangle imgback = pos;
                        imgback.Inflate(3, 3);
                        g.FillRectangle(SystemBrushes.Window, imgback);
                        // Image border
                        if (img.Width > 32 && img.Height > 32)
                        {
                            using (Pen pen = new Pen(Color.FromArgb(224, 224, 244)))
                            {
                                g.DrawRectangle(pen, imgback.X, imgback.Y, imgback.Width - 1, imgback.Height - 1);
                            }
                        }
                        // Image
                        g.DrawImage(img, pos);
                    }

                    // Draw item text
                    Size szt = TextRenderer.MeasureText(item.Text, ImageListView.Font);
                    Rectangle rt = new Rectangle(
                        bounds.Left + itemPadding.Width, bounds.Top + 2 * itemPadding.Height + ImageListView.ThumbnailSize.Height,
                        ImageListView.ThumbnailSize.Width, szt.Height);
                    Color textColor = this.ImageListView._palette.GetContentShortTextColor1(PaletteContentStyle.ButtonListItem, GetButtonState(state));
                    TextRenderer.DrawText(g, item.Text, ImageListView.Font, rt, textColor,
                        TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);
                }
                else // if (ImageListView.View == View.Details)
                {
                    List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();

                    // Separators
                    int x = bounds.Left - 2;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        x += column.Width;
                        if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                        {
                            using (Pen pGray32 = new Pen(Color.FromArgb(32, 128, 128, 128)))
                            {
                                g.DrawLine(pGray32, x, bounds.Top, x, bounds.Bottom);
                            }
                        }
                    }
                    Size offset = new Size(2, (bounds.Height - ImageListView.Font.Height) / 2);
                    // Sub text
                    int firstWidth = 0;
                    if (uicolumns.Count > 0)
                        firstWidth = uicolumns[0].Width;
                    Rectangle rt = new Rectangle(bounds.Left + offset.Width, bounds.Top + offset.Height, firstWidth - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        rt.Width = column.Width - 2 * offset.Width;
                        using (Brush bItemFore = new SolidBrush(SystemColors.ControlText))
                        {
                            int iconOffset = 0;
                            if (column.Type == ColumnType.Name)
                            {
                                // Allocate space for checkbox and file icon
                                if (ImageListView.ShowCheckBoxes && ImageListView.ShowFileIcons)
                                    iconOffset += 2 * 16 + 3 * 2;
                                else if (ImageListView.ShowCheckBoxes)
                                    iconOffset += 16 + 2 * 2;
                                else if (ImageListView.ShowFileIcons)
                                    iconOffset += 16 + 2 * 2;
                            }
                            rt.X += iconOffset;
                            rt.Width -= iconOffset;
                            // Rating stars
                            if (column.Type == ColumnType.Rating && ImageListView.RatingImage != null && ImageListView.EmptyRatingImage != null)
                            {
                                int rating = item.GetSimpleRating();
                                if (rating > 0)
                                {
                                    int w = ImageListView.RatingImage.Width;
                                    int y = (int)(rt.Top + (rt.Height - ImageListView.RatingImage.Height) / 2.0f);

                                    for (int i = 1; i <= 5; i++)
                                    {
                                        if (rating >= i)
                                            g.DrawImage(ImageListView.RatingImage, rt.Left + (i - 1) * w, y);
                                        else
                                            g.DrawImage(ImageListView.EmptyRatingImage, rt.Left + (i - 1) * w, y);
                                    }
                                }
                            }
                            else if (column.Type == ColumnType.Custom)
                                TextRenderer.DrawText(g, item.GetSubItemText(column.Guid), ImageListView.Font, rt, SystemColors.ControlText,
                                    TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);
                            else
                                TextRenderer.DrawText(g, item.GetSubItemText(column.Type), ImageListView.Font, rt, SystemColors.ControlText,
                                    TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping);

                            rt.X -= iconOffset;
                        }
                        rt.X += column.Width;
                    }
                }

                // Focus rectangle
                //if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                //{
                //    Rectangle focusBounds = bounds;
                //    focusBounds.Inflate(-2, -2);
                //    ControlPaint.DrawFocusRectangle(g, focusBounds);
                //}

                //else
                //    base.DrawItem(g, item, state, bounds);
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                // Fill with item background color
                if (item.BackColor != Color.Transparent)
                {
                    using (Brush brush = new SolidBrush(item.BackColor))
                    {
                        g.FillRectangle(brush, bounds);
                    }
                }

                if (ImageListView.View == View.Details)
                {
                    // Item background
                    if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                                                                     Color.FromArgb(64, 96, 160), Color.FromArgb(64, 64, 96, 160), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }
                    else if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(bounds,
                                                                     Color.FromArgb(64, Color.White), Color.FromArgb(16, Color.White), LinearGradientMode.Horizontal))
                        {
                            g.FillRectangle(brush, bounds);
                        }
                    }

                    // Shade sort column
                    List <ImageListView.ImageListViewColumnHeader> uicolumns = mImageListView.Columns.GetDisplayedColumns();
                    int x = mImageListView.layoutManager.ColumnHeaderBounds.Left;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        if (mImageListView.SortColumn == column.Type && mImageListView.SortOrder != SortOrder.None &&
                            (state & ItemState.Hovered) == ItemState.None && (state & ItemState.Selected) == ItemState.None)
                        {
                            Rectangle subItemBounds = bounds;
                            subItemBounds.X     = x;
                            subItemBounds.Width = column.Width;
                            using (Brush brush = new SolidBrush(Color.FromArgb(32, 128, 128, 128)))
                            {
                                g.FillRectangle(brush, subItemBounds);
                            }
                            break;
                        }
                        x += column.Width;
                    }
                    // Separators
                    x = mImageListView.layoutManager.ColumnHeaderBounds.Left;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        x += column.Width;
                        if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                        {
                            using (Pen pen = new Pen(Color.FromArgb(64, 128, 128, 128)))
                            {
                                g.DrawLine(pen, x, bounds.Top, x, bounds.Bottom);
                            }
                        }
                    }

                    // Item texts
                    Size offset = new Size(2, (bounds.Height - mImageListView.Font.Height) / 2);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.Alignment     = StringAlignment.Near;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        // Sub text
                        RectangleF rt = new RectangleF(bounds.Left + offset.Width, bounds.Top + offset.Height, uicolumns[0].Width - 2 * offset.Width, bounds.Height - 2 * offset.Height);
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            rt.Width = column.Width - 2 * offset.Width;
                            using (Brush bItemFore = new SolidBrush(Color.White))
                            {
                                g.DrawString(item.GetSubItemText(column.Type), mImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.X += column.Width;
                        }
                    }

                    // Border
                    if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(128, Color.White)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.Hovered)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(96, 144, 240)))
                        {
                            g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                        }
                    }
                }
                else
                {
                    // Align images to bottom of bounds
                    Image     img = item.ThumbnailImage;
                    Rectangle pos = Utility.GetSizedImageBounds(img,
                                                                new Rectangle(bounds.X + padding, bounds.Y + padding, bounds.Width - 2 * padding, bounds.Height - 2 * padding - mReflectionSize),
                                                                50.0f, 100.0f);

                    int x = pos.X;
                    int y = pos.Y;

                    // Item background
                    if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(
                                   new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                   Color.FromArgb(64, 96, 160), Color.FromArgb(16, 16, 16)))
                        {
                            g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                        }
                    }
                    else if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(
                                   new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                   Color.FromArgb(64, Color.White), Color.FromArgb(16, 16, 16)))
                        {
                            g.FillRectangle(brush, x - padding, y - padding, pos.Width + 2 * padding, pos.Height + 2 * padding);
                        }
                    }

                    // Border
                    if ((state & ItemState.Hovered) == ItemState.Hovered)
                    {
                        using (Brush brush = new LinearGradientBrush(
                                   new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                   Color.FromArgb(128, Color.White), Color.FromArgb(16, 16, 16)))
                            using (Pen pen = new Pen(brush))
                            {
                                g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                            }
                    }
                    else if ((state & ItemState.Selected) == ItemState.Selected)
                    {
                        using (Brush brush = new LinearGradientBrush(
                                   new Point(x - padding, y - padding), new Point(x - padding, y + pos.Height + 2 * padding),
                                   Color.FromArgb(96, 144, 240), Color.FromArgb(16, 16, 16)))
                            using (Pen pen = new Pen(brush))
                            {
                                g.DrawRectangle(pen, x - padding, y - padding + 1, pos.Width + 2 * padding - 1, pos.Height + 2 * padding - 1);
                            }
                    }

                    // Draw item image
                    DrawImageWithReflection(g, img, pos, mReflectionSize);
                    DrawThumbnail(g, item, img, pos, drawThumbnail: false);


                    // Highlight
                    using (Pen pen = new Pen(Color.FromArgb(160, Color.White)))
                    {
                        g.DrawLine(pen, pos.X, pos.Y + 1, pos.X + pos.Width - 1, pos.Y + 1);
                        g.DrawLine(pen, pos.X, pos.Y + 1, pos.X, pos.Y + pos.Height);
                    }
                }
            }
            /// <summary>
            /// Draws the left pane in Pane view mode.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="image">The image to draw.</param>
            /// <param name="bounds">The bounding rectangle of the pane.</param>
            public override void DrawPane(Graphics g, ImageListViewItem item, Image image, Rectangle bounds)
            {
                // Draw resize handle
                using (Brush bBorder = new SolidBrush(Color.FromArgb(64, 64, 64)))
                {
                    g.FillRectangle(bBorder, bounds.Right - 2, bounds.Top, 2, bounds.Height);
                }
                bounds.Width -= 2;

                if (item != null && image != null)
                {
                    // Calculate image bounds
                    Size      itemMargin = MeasureItemMargin(ImageListView.View);
                    Rectangle pos        = Utility.GetSizedImageBounds(image, new Rectangle(bounds.Location + itemMargin, bounds.Size - itemMargin - itemMargin), 50.0f, 0.0f);
                    // Draw image
                    g.DrawImage(image, pos);

                    bounds.X      += itemMargin.Width;
                    bounds.Width  -= 2 * itemMargin.Width;
                    bounds.Y       = pos.Height + 16;
                    bounds.Height -= pos.Height + 16;

                    // Item text
                    if (mImageListView.Columns[ColumnType.FileName].Visible && bounds.Height > 0)
                    {
                        int y = Utility.DrawStringPair(g, bounds, "", item.Text, mImageListView.Font,
                                                       Brushes.White, Brushes.White);
                        bounds.Y      += 2 * y;
                        bounds.Height -= 2 * y;
                    }

                    // File type
                    if (mImageListView.Columns[ColumnType.FileType].Visible && bounds.Height > 0 && !string.IsNullOrWhiteSpace(item.FileType))
                    {
                        using (Brush bCaption = new SolidBrush(Color.FromArgb(196, 196, 196)))
                            using (Brush bText = new SolidBrush(Color.White))
                            {
                                int y = Utility.DrawStringPair(g, bounds, mImageListView.Columns[ColumnType.FileType].Text + ": ",
                                                               item.FileType, mImageListView.Font, bCaption, bText);
                                bounds.Y      += y;
                                bounds.Height -= y;
                            }
                    }

                    // Metatada
                    foreach (ImageListView.ImageListViewColumnHeader column in mImageListView.Columns)
                    {
                        if (column.Type == ColumnType.MediaDescription)
                        {
                            bounds.Y      += 8;
                            bounds.Height -= 8;
                        }

                        if (bounds.Height <= 0)
                        {
                            break;
                        }

                        if (column.Visible &&
                            column.Type != ColumnType.FileType &&
                            column.Type != ColumnType.FileDateCreated &&
                            column.Type != ColumnType.FileFullPath &&
                            column.Type != ColumnType.FileDirectory &&
                            column.Type != ColumnType.FileName)
                        {
                            string caption = column.Text;
                            string text    = item.GetSubItemText(column.Type);
                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                using (Brush bCaption = new SolidBrush(Color.FromArgb(196, 196, 196)))
                                    using (Brush bText = new SolidBrush(Color.White))
                                    {
                                        int y = Utility.DrawStringPair(g, bounds, caption + ": ", text,
                                                                       mImageListView.Font, bCaption, bText);
                                        bounds.Y      += y;
                                        bounds.Height -= y;
                                    }
                            }
                        }
                    }
                }
            }
Esempio n. 15
0
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    // Zoom on mouse over
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        bounds.Inflate((int)(bounds.Width * mZoomRatio), (int)(bounds.Height * mZoomRatio));
                        if (bounds.Bottom > ItemAreaBounds.Bottom)
                        {
                            bounds.Y = ItemAreaBounds.Bottom - bounds.Height;
                        }
                        if (bounds.Top < ItemAreaBounds.Top)
                        {
                            bounds.Y = ItemAreaBounds.Top;
                        }
                        if (bounds.Right > ItemAreaBounds.Right)
                        {
                            bounds.X = ItemAreaBounds.Right - bounds.Width;
                        }
                        if (bounds.Left < ItemAreaBounds.Left)
                        {
                            bounds.X = ItemAreaBounds.Left;
                        }
                    }

                    // Get item image
                    Image img = null;

                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        img = GetImageAsync(item, new Size(bounds.Width - 8, bounds.Height - 8));
                    }

                    if (img == null)
                    {
                        img = item.ThumbnailImage;
                    }

                    // Calculate image bounds
                    Rectangle pos         = Utility.GetSizedImageBounds(img, Rectangle.Inflate(bounds, -4, -4));
                    int       imageWidth  = pos.Width;
                    int       imageHeight = pos.Height;
                    int       imageX      = pos.X;
                    int       imageY      = pos.Y;

                    // Allocate space for item text
                    if ((state & ItemState.Hovered) != ItemState.None &&
                        (bounds.Height - imageHeight) / 2 < ImageListView.Font.Height + 8)
                    {
                        int delta = (ImageListView.Font.Height + 8) - (bounds.Height - imageHeight) / 2;
                        bounds.Height += 2 * delta;
                        imageY        += delta;
                    }

                    // Paint background
                    using (Brush bBack = new SolidBrush(ImageListView.BackColor))
                    {
                        Utility.FillRoundedRectangle(g, bBack, bounds, 5);
                    }
                    using (Brush bItemBack = new SolidBrush(item.BackColor))
                    {
                        Utility.FillRoundedRectangle(g, bItemBack, bounds, 5);
                    }
                    if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 5);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 5);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 5);
                        }
                    }

                    // Draw the image
                    //g.DrawImage(img, pos);
                    DrawThumbnail(g, item, img, pos);

                    // Draw image border
                    if (Math.Min(imageWidth, imageHeight) > 32)
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, Color.Gray)))
                        {
                            g.DrawRectangle(pGray128, imageX, imageY, imageWidth, imageHeight);
                        }
                        if (System.Math.Min(imageWidth, imageHeight) > 32)
                        {
                            using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                            {
                                g.DrawRectangle(pWhite128, imageX + 1, imageY + 1, imageWidth - 2, imageHeight - 2);
                            }
                        }
                    }

                    // Draw item text
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt               = new RectangleF(bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, (bounds.Height - imageHeight) / 2 - 8);
                            sf.Alignment     = StringAlignment.Center;
                            sf.FormatFlags   = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming      = StringTrimming.EllipsisCharacter;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, ImageListView.Font, bItemFore, rt, sf);
                            }
                            rt.Y = bounds.Bottom - (bounds.Height - imageHeight) / 2 + 4;
                            string details = "";
                            if (item.Dimensions != Size.Empty)
                            {
                                details += item.GetSubItemText(ColumnType.MediaDimensions) + " pixels ";
                            }
                            if (item.FileSize != 0)
                            {
                                details += item.GetSubItemText(ColumnType.FileSize);
                            }
                            using (Brush bGrayText = new SolidBrush(Color.Gray))
                            {
                                g.DrawString(details, ImageListView.Font, bGrayText, rt, sf);
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                }
                else
                {
                    base.DrawItem(g, item, state, bounds);
                }
            }
            /// <summary>
            /// Draws the left pane in Pane view mode.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="image">The image to draw.</param>
            /// <param name="bounds">The bounding rectangle of the pane.</param>
            public override void DrawPane(Graphics g, ImageListViewItem item, Image image, Rectangle bounds)
            {
                // Draw resize handle
                using (Brush bBorder = new SolidBrush(Color.FromArgb(64, 64, 64)))
                {
                    g.FillRectangle(bBorder, bounds.Right - 2, bounds.Top, 2, bounds.Height);
                }
                bounds.Width -= 2;

                if (item != null && image != null)
                {
                    // Calculate image bounds
                    Size itemMargin = MeasureItemMargin(ImageListView.View);
                    Rectangle pos = Utility.GetSizedImageBounds(image, new Rectangle(bounds.Location + itemMargin, bounds.Size - itemMargin - itemMargin), 50.0f, 0.0f);
                    // Draw image
                    g.DrawImage(image, pos);

                    bounds.X += itemMargin.Width;
                    bounds.Width -= 2 * itemMargin.Width;
                    bounds.Y = pos.Height + 16;
                    bounds.Height -= pos.Height + 16;

                    // Item text
                    if (mImageListView.Columns[ColumnType.Name].Visible && bounds.Height > 0)
                    {
                        int y = Utility.DrawStringPair(g, bounds, "", item.Text, mImageListView.Font,
                            Brushes.White, Brushes.White);
                        bounds.Y += 2 * y;
                        bounds.Height -= 2 * y;
                    }

                    // File type
                    if (mImageListView.Columns[ColumnType.FileType].Visible && bounds.Height > 0 && !string.IsNullOrEmpty(item.FileType))
                    {
                        using (Brush bCaption = new SolidBrush(Color.FromArgb(196, 196, 196)))
                        using (Brush bText = new SolidBrush(Color.White))
                        {
                            int y = Utility.DrawStringPair(g, bounds, mImageListView.Columns[ColumnType.FileType].Text + ": ",
                                item.FileType, mImageListView.Font, bCaption, bText);
                            bounds.Y += y;
                            bounds.Height -= y;
                        }
                    }

                    // Metatada
                    foreach (ImageListView.ImageListViewColumnHeader column in mImageListView.Columns)
                    {
                        if (column.Type == ColumnType.ImageDescription)
                        {
                            bounds.Y += 8;
                            bounds.Height -= 8;
                        }

                        if (bounds.Height <= 0) break;

                        if (column.Visible &&
                            column.Type != ColumnType.FileType &&
                            column.Type != ColumnType.DateAccessed &&
                            column.Type != ColumnType.FileName &&
                            column.Type != ColumnType.FilePath &&
                            column.Type != ColumnType.Name)
                        {
                            string caption = column.Text;
                            string text = item.GetSubItemText(column.Type);
                            if (!string.IsNullOrEmpty(text))
                            {
                                using (Brush bCaption = new SolidBrush(Color.FromArgb(196, 196, 196)))
                                using (Brush bText = new SolidBrush(Color.White))
                                {
                                    int y = Utility.DrawStringPair(g, bounds, caption + ": ", text,
                                        mImageListView.Font, bCaption, bText);
                                    bounds.Y += y;
                                    bounds.Height -= y;
                                }
                            }
                        }
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    Size itemPadding = new Size(4, 4);

                    // Paint background
                    using (Brush bItemBack = new SolidBrush(item.BackColor))
                    {
                        g.FillRectangle(bItemBack, bounds);
                    }
                    if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 4);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 4);
                        }
                    }

                    // Draw the image
                    Image img = item.ThumbnailImage;
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize), 0.0f, 50.0f);
                        g.DrawImage(img, pos);
                        // Draw image border
                        if (Math.Min(pos.Width, pos.Height) > 32)
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, Color.Gray)))
                            {
                                g.DrawRectangle(pGray128, pos);
                            }
                            using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                            {
                                g.DrawRectangle(pWhite128, Rectangle.Inflate(pos, -1, -1));
                            }
                        }

                        // Draw item text
                        int lineHeight = CaptionFont.Height;
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt = new RectangleF(bounds.Left + 2 * itemPadding.Width + ImageListView.ThumbnailSize.Width,
                                bounds.Top + itemPadding.Height + (Math.Max(ImageListView.ThumbnailSize.Height, mTextHeight) - mTextHeight) / 2,
                                mTileWidth, lineHeight);
                            sf.Alignment = StringAlignment.Near;
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming = StringTrimming.EllipsisCharacter;
                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.Text, CaptionFont, bItemFore, rt, sf);
                            }
                            using (Brush bItemDetails = new SolidBrush(Color.Gray))
                            {
                                rt.Offset(0, 1.5f * lineHeight);
                                if (!string.IsNullOrEmpty(item.FileType))
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.FileType),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.Dimensions != Size.Empty || item.Resolution != SizeF.Empty)
                                {
                                    string text = "";
                                    if (item.Dimensions != Size.Empty)
                                        text += item.GetSubItemText(ColumnType.Dimensions) + " pixels ";
                                    if (item.Resolution != SizeF.Empty)
                                        text += item.Resolution.Width + " dpi";
                                    g.DrawString(text, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.FileSize != 0)
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.FileSize),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                if (item.DateModified != DateTime.MinValue)
                                {
                                    g.DrawString(item.GetSubItemText(ColumnType.DateModified),
                                        ImageListView.Font, bItemDetails, rt, sf);
                                }
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        ControlPaint.DrawFocusRectangle(g, bounds);
                    }
                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == View.Details)
                {
                    bool alternate = (item.Index % 2 == 1);
                    List<ImageListView.ImageListViewColumnHeader> uicolumns = ImageListView.Columns.GetDisplayedColumns();

                    // Paint background
                    if ((state & ItemState.Disabled) != ItemState.None)
                    {
                        // Disabled
                        using (Brush bItemBack = new LinearGradientBrush(bounds, ImageListView.Colors.DisabledColor1,
                            ImageListView.Colors.DisabledColor2, LinearGradientMode.Vertical))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }
                    else if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        // Focused and selected
                        using (Brush bItemBack = new LinearGradientBrush(bounds, ImageListView.Colors.SelectedColor1,
                            ImageListView.Colors.SelectedColor2, LinearGradientMode.Vertical))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        // Not focused and selected
                        using (Brush bItemBack = new LinearGradientBrush(bounds, ImageListView.Colors.UnFocusedColor1,
                            ImageListView.Colors.UnFocusedColor2, LinearGradientMode.Vertical))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }
                    else
                    {
                        // Not selected
                        using (Brush bItemBack = new SolidBrush(alternate ?
                            ImageListView.Colors.AlternateBackColor : ImageListView.Colors.BackColor))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }

                        // Shade sort column
                        int x = bounds.Left - 1;
                        foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                        {
                            if (ImageListView.SortOrder != SortOrder.None &&
                                ImageListView.SortColumn >= 0 && ImageListView.SortColumn < ImageListView.Columns.Count &&
                                ImageListView.Columns[ImageListView.SortColumn].Guid == column.Guid)
                            {
                                Rectangle subItemBounds = bounds;
                                subItemBounds.X = x;
                                subItemBounds.Width = column.Width;
                                using (Brush bSort = new SolidBrush(ImageListView.Colors.ColumnSelectColor))
                                {
                                    g.FillRectangle(bSort, subItemBounds);
                                }
                                break;
                            }
                            x += column.Width;
                        }

                    }

                    // Separators
                    int xs = bounds.Left - 1;
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        xs += column.Width;
                        if (!ReferenceEquals(column, uicolumns[uicolumns.Count - 1]))
                        {
                            using (Pen pSep = new Pen(ImageListView.Colors.ColumnSeparatorColor))
                            {
                                g.DrawLine(pSep, xs, bounds.Top, xs, bounds.Bottom);
                            }
                        }
                    }

                    // Sub items
                    Color foreColor = ImageListView.Colors.CellForeColor;
                    if ((state & ItemState.Disabled) != ItemState.None)
                        foreColor = ImageListView.Colors.DisabledForeColor;
                    else if (ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
                        foreColor = ImageListView.Colors.SelectedForeColor;
                    else if (!ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
                        foreColor = ImageListView.Colors.UnFocusedForeColor;
                    else if (alternate)
                        foreColor = ImageListView.Colors.AlternateCellForeColor;

                    int offset = 2;
                    int firstWidth = 0;
                    if (uicolumns.Count > 0)
                        firstWidth = uicolumns[0].Width;
                    Rectangle rt = new Rectangle(bounds.Left + offset, bounds.Top, firstWidth - 2 * offset, bounds.Height);
                    foreach (ImageListView.ImageListViewColumnHeader column in uicolumns)
                    {
                        rt.Width = column.Width - 2 * offset;
                        int iconOffset = 0;
                        if (column.Type == ColumnType.Name)
                        {
                            // Allocate space for checkbox and file icon
                            if (ImageListView.ShowCheckBoxes && ImageListView.ShowFileIcons)
                                iconOffset += 2 * 16 + 3 * 2;
                            else if (ImageListView.ShowCheckBoxes)
                                iconOffset += 16 + 2 * 2;
                            else if (ImageListView.ShowFileIcons)
                                iconOffset += 16 + 2 * 2;
                        }
                        rt.X += iconOffset;
                        rt.Width -= iconOffset;
                        // Rating stars
                        if (column.Type == ColumnType.Rating && ImageListView.RatingImage != null && ImageListView.EmptyRatingImage != null)
                        {
                            int rating = item.GetSimpleRating();
                            if (rating > 0)
                            {
                                int w = ImageListView.RatingImage.Width;
                                int y = (int)(rt.Top + (rt.Height - ImageListView.RatingImage.Height) / 2.0f);

                                for (int i = 1; i <= 5; i++)
                                {
                                    if (rating >= i)
                                        g.DrawImage(ImageListView.RatingImage, rt.Left + (i - 1) * w, y);
                                    else
                                        g.DrawImage(ImageListView.EmptyRatingImage, rt.Left + (i - 1) * w, y);
                                }
                            }
                        }
                        else if (column.Type == ColumnType.Custom)
                            TextRenderer.DrawText(g, item.GetSubItemText(column.Guid), ImageListView.Font, rt, foreColor,
                                TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsClipping);
                        else
                            TextRenderer.DrawText(g, item.GetSubItemText(column.Type), ImageListView.Font, rt, foreColor,
                                TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsClipping);

                        rt.X -= iconOffset;
                        rt.X += column.Width;
                    }

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                        ControlPaint.DrawFocusRectangle(g, bounds);
                }
                else // if (ImageListView.View != View.Details)
                {
                    // Paint background
                    if (ImageListView.Enabled)
                    {
                        using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }
                    else
                    {
                        using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }

                    // Get thumbnail
                    Image img = item.GetCachedImage(CachedImageType.Thumbnail);

                    // Reference text height
                    int textHeight = ImageListView.Font.Height;

                    // Calculate bounds
                    Rectangle textBounds = new Rectangle(bounds.Left + 3, bounds.Bottom - (textHeight + 3), bounds.Width - 2 * 3, textHeight);
                    Rectangle imgBounds;
                    if (img != null)
                        imgBounds = new Rectangle(bounds.Left + (bounds.Width - img.Width) / 2,
                            bounds.Bottom - (img.Height + textHeight + 3 * 3), img.Width, img.Height);
                    else
                        imgBounds = new Rectangle(bounds.Left + 3, bounds.Top + 3, ImageListView.ThumbnailSize.Width, ImageListView.ThumbnailSize.Height);
                    Rectangle textOutline = Rectangle.Inflate(textBounds, 3, 3);
                    Rectangle imgOutline = Rectangle.Inflate(imgBounds, 3, 3);
                    textOutline.Width -= 1;
                    textOutline.Height -= 1;

                    // Paint background
                    if ((((state & ItemState.Disabled) != ItemState.None)))
                    {
                        // Disabled
                        using (Brush bBack = new SolidBrush(ImageListView.Colors.DisabledColor1))
                        {
                            Utility.FillRoundedRectangle(g, bBack, textOutline, 4);
                            Utility.FillRoundedRectangle(g, bBack, imgOutline, 4);
                        }
                    }
                    else if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)))
                    {
                        // Focused and selected
                        using (Brush bBack = new SolidBrush(ImageListView.Colors.SelectedColor1))
                        {
                            Utility.FillRoundedRectangle(g, bBack, textOutline, 4);
                            Utility.FillRoundedRectangle(g, bBack, imgOutline, 4);
                        }
                    }
                    else if ((!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)))
                    {
                        // Not focused and selected
                        using (Brush bBack = new SolidBrush(ImageListView.Colors.UnFocusedColor1))
                        {
                            Utility.FillRoundedRectangle(g, bBack, textOutline, 4);
                            Utility.FillRoundedRectangle(g, bBack, imgOutline, 4);
                        }
                    }

                    // Draw image
                    if (img != null)
                    {
                        g.DrawImage(img, imgBounds.Location);
                    }

                    // Image border
                    using (Pen pBorder = new Pen(ImageListView.Colors.BorderColor))
                    {
                        Utility.DrawRoundedRectangle(g, pBorder, imgOutline.Left, imgOutline.Top, imgOutline.Width - 1, imgOutline.Height - 1, 3);
                    }

                    // Hovered state
                    if ((state & ItemState.Hovered) != ItemState.None)
                    {
                        using (Brush bGlow = new SolidBrush(Color.FromArgb(24, Color.White)))
                        {
                            Utility.FillRoundedRectangle(g, bGlow, imgOutline, 4);
                        }
                    }

                    // Item text
                    Color foreColor = ImageListView.Colors.ForeColor;
                    if ((state & ItemState.Disabled) != ItemState.None)
                        foreColor = ImageListView.Colors.DisabledForeColor;
                    else if (ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
                        foreColor = ImageListView.Colors.SelectedForeColor;
                    else if (!ImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
                        foreColor = ImageListView.Colors.UnFocusedForeColor;
                    TextRenderer.DrawText(g, item.Text, ImageListView.Font, textBounds, foreColor,
                        TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsClipping);

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        textOutline.Offset(1, 1);
                        textOutline.Width -= 1;
                        textOutline.Height -= 1;
                        ControlPaint.DrawFocusRectangle(g, textOutline);
                    }
                }
            }
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    Size itemPadding = new Size(4, 4);

                    // Paint background
                    if (ImageListView.Enabled)
                    {
                        using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }
                    else
                    {
                        using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
                        {
                            g.FillRectangle(bItemBack, bounds);
                        }
                    }

                    // Paint background Disabled
                    if ((state & ItemState.Disabled) != ItemState.None)
                    {
                        using (Brush bDisabled = new LinearGradientBrush(bounds, ImageListView.Colors.DisabledColor1, ImageListView.Colors.DisabledColor2, LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bDisabled, bounds, 4);
                        }
                    }
                    else if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, ImageListView.Colors.SelectedColor1, ImageListView.Colors.SelectedColor2, LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, ImageListView.Colors.UnFocusedColor1, ImageListView.Colors.UnFocusedColor2, LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 4);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, ImageListView.Colors.HoverColor1, ImageListView.Colors.HoverColor2, LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 4);
                        }
                    }

                    // Draw the image
                    Image img = item.GetCachedImage(CachedImageType.Thumbnail);
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize), 0.0f, 50.0f);
                        g.DrawImage(img, pos);
                        // Draw image border
                        if (Math.Min(pos.Width, pos.Height) > 32)
                        {
                            using (Pen pOuterBorder = new Pen(ImageListView.Colors.ImageOuterBorderColor))
                            {
                                g.DrawRectangle(pOuterBorder, pos);
                            }
                            if (System.Math.Min(ImageListView.ThumbnailSize.Width, ImageListView.ThumbnailSize.Height) > 32)
                            {
                                using (Pen pInnerBorder = new Pen(ImageListView.Colors.ImageInnerBorderColor))
                                {
                                    g.DrawRectangle(pInnerBorder, Rectangle.Inflate(pos, -1, -1));
                                }
                            }
                        }
                    }

                    // Draw item text
                    int lineHeight = CaptionFont.Height;
                    RectangleF rt;
                    using (StringFormat sf = new StringFormat())
                    {
                        rt = new RectangleF(bounds.Left + 2 * itemPadding.Width + ImageListView.ThumbnailSize.Width,
                            bounds.Top + itemPadding.Height + (Math.Max(ImageListView.ThumbnailSize.Height, mTextHeight) - mTextHeight) / 2,
                            mTileWidth, lineHeight);
                        sf.Alignment = StringAlignment.Near;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming = StringTrimming.EllipsisCharacter;
                        Color foreColor = ImageListView.Colors.ForeColor;
                        if ((state & ItemState.Disabled) != ItemState.None)
                        {
                            foreColor = ImageListView.Colors.DisabledForeColor;
                        }
                        using (Brush bItemFore = new SolidBrush(foreColor))
                        {
                            g.DrawString(item.Text, CaptionFont, bItemFore, rt, sf);
                        }
                        using (Brush bItemDetails = new SolidBrush(ImageListView.Colors.PaneLabelColor))
                        {
                            rt.Offset(0, 1.5f * lineHeight);
                            string fileType = item.GetSubItemText(ColumnType.FileType);
                            if (!string.IsNullOrEmpty(fileType))
                            {
                                g.DrawString(fileType, ImageListView.Font, bItemDetails, rt, sf);
                                rt.Offset(0, 1.1f * lineHeight);
                            }
                            string dimensions = item.GetSubItemText(ColumnType.Dimensions);
                            string resolution = item.GetSubItemText(ColumnType.Resolution);
                            if (!string.IsNullOrEmpty(dimensions) || !string.IsNullOrEmpty(resolution))
                            {
                                string text = "";
                                if (!string.IsNullOrEmpty(dimensions))
                                    text += dimensions + " pixels ";
                                if (!string.IsNullOrEmpty(resolution))
                                    text += resolution.Split(new char[] { ' ', 'x' }, StringSplitOptions.RemoveEmptyEntries)[0] + " dpi";
                                g.DrawString(text, ImageListView.Font, bItemDetails, rt, sf);
                                rt.Offset(0, 1.1f * lineHeight);
                            }
                            string fileSize = item.GetSubItemText(ColumnType.FileSize);
                            if (!string.IsNullOrEmpty(fileSize))
                            {
                                g.DrawString(fileSize, ImageListView.Font, bItemDetails, rt, sf);
                                rt.Offset(0, 1.1f * lineHeight);
                            }
                            string dateModified = item.GetSubItemText(ColumnType.DateModified);
                            if (!string.IsNullOrEmpty(dateModified))
                            {
                                g.DrawString(dateModified, ImageListView.Font, bItemDetails, rt, sf);
                            }
                        }
                    }

                    // Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, ImageListView.Colors.ControlBackColor)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (((state & ItemState.Disabled) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(ImageListView.Colors.DisabledBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(ImageListView.Colors.SelectedBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(ImageListView.Colors.UnFocusedBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(ImageListView.Colors.BorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(ImageListView.Colors.HoverBorderColor))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    // Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        ControlPaint.DrawFocusRectangle(g, bounds);
                    }
                }
                else
                    base.DrawItem(g, item, state, bounds);
            }
Esempio n. 20
0
            /// <summary>
            /// Draws the specified item on the given graphics.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics to draw on.</param>
            /// <param name="item">The ImageListViewItem to draw.</param>
            /// <param name="state">The current view state of item.</param>
            /// <param name="bounds">The bounding rectangle of item in client coordinates.</param>
            public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
            {
                if (ImageListView.View == Manina.Windows.Forms.View.Thumbnails)
                {
                    Size itemPadding = new Size(4, 4);

                    #region Paint background
                    using (Brush bItemBack = new SolidBrush(item.BackColor))
                    {
                        g.FillRectangle(bItemBack, bounds);
                    }
                    if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
                        (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                    {
                        using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bSelected, bounds, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bGray64, bounds, 4);
                        }
                    }
                    if (((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        {
                            Utility.FillRoundedRectangle(g, bHovered, bounds, 4);
                        }
                    }
                    #endregion

                    #region Draw the image and Title(s)
                    Image img = item.ThumbnailImage;
                    if (img != null)
                    {
                        Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize), 0.0f, 50.0f);
                        g.DrawImage(img, pos);

                        DrawThumbnail(g, item, img, pos);

                        // Draw image border
                        if (Math.Min(pos.Width, pos.Height) > 32)
                        {
                            using (Pen pGray128 = new Pen(Color.FromArgb(128, Color.Gray)))
                            {
                                g.DrawRectangle(pGray128, pos);
                            }
                            using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                            {
                                g.DrawRectangle(pWhite128, Rectangle.Inflate(pos, -1, -1));
                            }
                        }

                        // Draw item text
                        int        lineHeight = CaptionFont.Height;
                        RectangleF rt;
                        using (StringFormat sf = new StringFormat())
                        {
                            rt = new RectangleF(bounds.Left + 2 * itemPadding.Width + ImageListView.ThumbnailSize.Width,
                                                bounds.Top + itemPadding.Height + (Math.Max(ImageListView.ThumbnailSize.Height, mTextHeight) - mTextHeight) / 2,
                                                mTileWidth, lineHeight);
                            sf.Alignment     = StringAlignment.Near;
                            sf.FormatFlags   = StringFormatFlags.NoWrap;
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Trimming      = StringTrimming.EllipsisCharacter;

                            using (Brush bItemFore = new SolidBrush(item.ForeColor))
                            {
                                g.DrawString(item.GetSubItemText(ImageListView.TitleLine1), CaptionFont, bItemFore, rt, sf);
                            }

                            using (Brush bItemDetails = new SolidBrush(Color.Gray))
                            {
                                //Line 2 :
                                rt.Offset(0, 1.5f * lineHeight);

                                string line;

                                try
                                {
                                    line = item.GetSubItemText(ImageListView.TitleLine2);
                                    g.DrawString(line, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);

                                    line = item.GetSubItemText(ImageListView.TitleLine3);
                                    g.DrawString(line, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);


                                    line = item.GetSubItemText(ImageListView.TitleLine4);
                                    g.DrawString(line, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);

                                    line = item.GetSubItemText(ImageListView.TitleLine5);
                                    g.DrawString(line, ImageListView.Font, bItemDetails, rt, sf);
                                    rt.Offset(0, 1.1f * lineHeight);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message); //For debug reason
                                    //Error can occure when ImageListView.Font
                                }
                            }
                        }
                    }
                    #endregion

                    #region Item border
                    using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    {
                        Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                    }
                    if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                    {
                        using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    else if ((state & ItemState.Selected) == ItemState.None)
                    {
                        using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        {
                            Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }

                    if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                    {
                        using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        {
                            Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                        }
                    }
                    #endregion

                    #region Focus rectangle
                    if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                    {
                        ControlPaint.DrawFocusRectangle(g, bounds);
                    }
                    #endregion
                }
                else
                {
                    Image img = item.ThumbnailImage; //JTN Added - Force image cahcing to be triggered
                    base.DrawItem(g, item, state, bounds);
                }
            }