private void FillIconListView(Icon icon) { iconList.Items.Clear(); if (icon == null) return; List<Icon> l = IconHelper.SplitGroupIcon(icon); foreach (Icon icn in l) { IconListViewItem item = new IconListViewItem(); item.Name = iconList.Items.Count.ToString().PadLeft(5, '0'); item.Icon = icn; iconList.Items.Add(item); } }
private void IconListView_DrawItem(object sender, DrawListViewItemEventArgs e) { IconListViewItem item = e.Item as IconListViewItem; if (item == null) { e.DrawDefault = true; return; } // Draw item e.DrawBackground(); Pen border = SystemPens.ControlLight; if (e.Item.Selected) { if (this.Focused) { border = SystemPens.Highlight; } else { border = SystemPens.ButtonFace; } } int centerSpacing = (e.Bounds.Width - this.TileSize.Width - TilePadding.Horizontal) / 2 + TilePadding.Left; Rectangle newBounds = new Rectangle(e.Bounds.X + centerSpacing, e.Bounds.Y + TilePadding.Top, this.TileSize.Width, this.TileSize.Height); e.Graphics.DrawRectangle(border, newBounds); //e.Graphics.DrawString("Whatever", this.Font, e., 0, 0); int x = e.Bounds.X + (newBounds.Width - item.Icon.Width) / 2 + centerSpacing + 1; int y = e.Bounds.Y + (newBounds.Height - item.Icon.Height) / 2 + TilePadding.Top + 1; Rectangle rect = new Rectangle(x, y, item.Icon.Width, item.Icon.Height); Region clipReg = new Region(newBounds); e.Graphics.Clip = clipReg; e.Graphics.DrawIcon(item.Icon, rect); string text = string.Format("{0} x {1}", item.Icon.Width, item.Icon.Height); SizeF stringSize = e.Graphics.MeasureString(text, this.Font); int stringWidth = (int)Math.Round(stringSize.Width); int stringHeight = (int)Math.Round(stringSize.Height); x = e.Bounds.X + (e.Bounds.Width - stringWidth - TilePadding.Horizontal) / 2 + TilePadding.Left; y = e.Bounds.Y + this.TileSize.Height + verticalSpacing + TilePadding.Top; clipReg = new Region(e.Bounds); e.Graphics.Clip = clipReg; if (e.Item.Selected) { if (this.Focused) { e.Graphics.FillRectangle(SystemBrushes.Highlight, x - 1, y - 1, stringWidth + 2, stringSize.Height + 2); e.Graphics.DrawString(text, this.Font, SystemBrushes.HighlightText, x, y); } else { e.Graphics.FillRectangle(SystemBrushes.ButtonFace, x - 1, y - 1, stringWidth + 2, stringSize.Height + 2); e.Graphics.DrawString(text, this.Font, SystemBrushes.ControlText, x, y); } } else { e.Graphics.DrawString(text, this.Font, SystemBrushes.ControlText, x, y); } }