/// <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 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(ImageListView.Colors.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, 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.ThumbnailImage; if (img != null) { Rectangle pos = 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)); } } } // Get DF image details string Description = "File info not found"; string RecordCount = "0"; if (null != MyLibraryInfoXmlDocument) { XmlNodeList Nodes = MyLibraryInfoXmlDocument.GetElementsByTagName(item.Text); if (Nodes.Count > 0) { Description = Nodes[0].InnerText; RecordCount = Nodes[0].Attributes["Records"].Value; } } // 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(ImageListView.Colors.ForeColor)) { // Draw filename g.DrawString(item.Text, CaptionFont, bItemFore, rt, sf); rt.Offset(0, 1.5f * lineHeight); } using (Brush bItemDetails = new SolidBrush(ImageListView.Colors.PaneLabelColor)) { // Draw description g.DrawString(Description, ImageListView.Font, bItemDetails, rt, sf); rt.Offset(0, 1.1f * lineHeight); // Draw record count g.DrawString(RecordCount + " records ", ImageListView.Font, bItemDetails, rt, sf); rt.Offset(0, 1.1f * lineHeight); } } } // 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 (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); } }
/// <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); } }