protected override void OnDrawItem(DrawListViewItemEventArgs e) { //We draw the current line of items (= item with subitems) on a temp bitmap, then draw the bitmap at once. This is to reduce flickering. using (Bitmap b = new Bitmap(e.Item.Bounds.Width, e.Item.Bounds.Height)) { using (Graphics g = Graphics.FromImage(b)) { if (e.State.HasFlag(ListViewItemStates.Selected)) { // selected background g.FillRectangle(SkinManager.GetFlatButtonPressedBackgroundBrush(), new Rectangle(new Point(0, 0), e.Bounds.Size)); } else if (e.Bounds.Contains(MouseLocation) && MouseState == MouseState.HOVER) { // hover background g.FillRectangle(SkinManager.GetFlatButtonHoverBackgroundBrush(), new Rectangle(new Point(0, 0), e.Bounds.Size)); } else { // draw item back color g.FillRectangle(new SolidBrush(e.Item.BackColor), new Rectangle(new Point(0, 0), e.Bounds.Size)); } // Draw separator g.DrawLine(new Pen(SkinManager.GetDividersColor()), e.Bounds.Left, 0, e.Bounds.Right, 0); // draw item e.Graphics.DrawImage(b, e.Item.Bounds.Location); } } }
private void listChars_DrawItem(object sender, System.Windows.Forms.DrawListViewItemEventArgs e) { if ((e.State & (ListViewItemStates.Selected | ListViewItemStates.Hot)) != 0) { e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Highlight, e.Bounds); } else { e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Info, e.Bounds); } e.Graphics.DrawRectangle(System.Drawing.Pens.Black, e.Bounds); Types.C64Character character = (Types.C64Character)e.Item.Tag; if (character == null) { return; } System.Drawing.Brush brush = System.Drawing.SystemBrushes.WindowText; if ((e.State & (ListViewItemStates.Selected | ListViewItemStates.Hot)) != 0) { brush = System.Drawing.SystemBrushes.HighlightText; } e.Graphics.DrawString(e.Item.Text, listChars.Font, brush, new System.Drawing.PointF(e.Bounds.Left + 2, e.Bounds.Top + 2)); e.Graphics.DrawString(character.PetSCIIValue.ToString("X02"), _DefaultFont, brush, new System.Drawing.PointF(e.Bounds.Left + 40, e.Bounds.Top + 2)); e.Graphics.DrawString(character.Desc, _DefaultFont, brush, new System.Drawing.PointF(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height * 0.5f)); if ((e.State & ListViewItemStates.Focused) != 0) { e.DrawFocusRectangle(); } }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { var item = (CustomListViewItem)Items[e.ItemIndex]; if (item.ImageList == null) return; var img = item.ImageList.Images[item.ImageIndex]; e.Graphics.DrawImage(img, item.Bounds.X, item.Bounds.Y); e.Graphics.DrawRectangle(pBlack, item.Bounds.X, item.Bounds.Y, img.Width, img.Height); if (item.Selected && item.SelectionOpacity < 255) item.SelectionOpacity += 5; if (!item.Selected && item.SelectionOpacity > 0) item.SelectionOpacity -= 5; Pen pBlue = new Pen(Color.FromArgb(item.SelectionOpacity, Color.DodgerBlue)) { Width = 3 }; GraphicsPath rounded = RoundedRectangle.Create(item.Bounds.X - 1, item.Bounds.Y - 1, img.Width + 2, img.Height + 1, 5); e.Graphics.DrawPath(pBlue, rounded); base.OnDrawItem(e); if (item.SelectionOpacity > 0 && item.SelectionOpacity < 255) Invalidate(); }
void listViewResults_DrawItem(object sender, DrawListViewItemEventArgs e) { if (0 != (e.State & ListViewItemStates.Selected)) { e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds); //ForeColor = Color.White; } else { //ForeColor = Color.Black; if (e.ItemIndex % 2 == 0) { e.Graphics.FillRectangle(Brushes.BlanchedAlmond, e.Bounds); } else { e.Graphics.FillRectangle(Brushes.White, e.Bounds); } if (0 != (e.State & ListViewItemStates.Focused)) { e.DrawFocusRectangle(); } } e.DrawText(); }
private void drawitem(object sender, DrawListViewItemEventArgs e) { int i = (int)e.Item.Tag; bool patched; Bitmap bmp = Textures.GetTexture(i, out patched); if (bmp != null) { int width = bmp.Width; int height = bmp.Height; if (width >= e.Bounds.Width) width = e.Bounds.Width - 2; if (height >= e.Bounds.Height) height = e.Bounds.Height - 2; e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, width, height)); if (listView1.SelectedItems.Contains(e.Item)) e.DrawFocusRectangle(); else if (patched) e.Graphics.DrawRectangle(Pens.LightCoral, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else e.Graphics.DrawRectangle(Pens.Gray, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); } }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { base.OnDrawItem(e); var item = e.Item as IconListViewItem; // Draw item e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.Clip = new Region(e.Bounds); if (e.Item.Selected) e.Graphics.FillRectangle(SystemBrushes.MenuHighlight, e.Bounds); int w = Math.Min(128, item.Bitmap.Width); int h = Math.Min(128, item.Bitmap.Height); int x = e.Bounds.X + (e.Bounds.Width - w) / 2; int y = e.Bounds.Y + (e.Bounds.Height - h) / 2; var dstRect = new Rectangle(x, y, w, h); var srcRect = new Rectangle(Point.Empty, item.Bitmap.Size); e.Graphics.DrawImage(item.Bitmap, dstRect, srcRect, GraphicsUnit.Pixel); var textRect = new Rectangle( e.Bounds.Left, e.Bounds.Bottom - Font.Height - 4, e.Bounds.Width, Font.Height + 2); TextRenderer.DrawText(e.Graphics, item.ToolTipText, Font, textRect, ForeColor); e.Graphics.Clip = new Region(); e.Graphics.DrawRectangle(SystemPens.ControlLight, e.Bounds); }
private void DrawItem(System.Windows.Forms.DrawListViewItemEventArgs e, InterlinLineSpec spec) { Brush backBrush = SystemBrushes.ControlLightLight; if (e.Item.Selected) { backBrush = SystemBrushes.Highlight; } e.Graphics.FillRectangle(backBrush, e.Bounds); if (e.Item.Focused) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } SolidBrush textBrush = GetBrush(spec, e.Item.Selected) as SolidBrush; try { Font drawFont = e.Item.Font; ListViewItem item = e.Item as ListViewItem; // Draw the line label. e.Graphics.DrawString(item.Text, drawFont, textBrush, e.Bounds); // Now draw the WritingSystem info. e.Graphics.DrawString(item.SubItems[1].Text, item.SubItems[1].Font, e.Item.Selected ? textBrush : SystemBrushes.ControlText, item.SubItems[1].Bounds); } finally { if (!e.Item.Selected) { textBrush.Dispose(); } } }
private void drawitem(object sender, DrawListViewItemEventArgs e) { int i = int.Parse(e.Item.Text.ToString()); Bitmap bmp; char c = (char)i; if ((int)treeView.SelectedNode.Parent.Tag == 1) // Unicode bmp = UnicodeFonts.Fonts[(int)treeView.SelectedNode.Tag].Chars[i].GetImage(); else bmp = (Bitmap)e.Item.Tag; if (listView1.SelectedItems.Contains(e.Item)) e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); e.Graphics.DrawString(c.ToString(), Fonts.DefaultFont, Brushes.Gray, e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Y + e.Bounds.Height / 2); if (bmp != null) { int width = bmp.Width; int height = bmp.Height; if (width > e.Bounds.Width) width = e.Bounds.Width - 2; if (height > e.Bounds.Height) height = e.Bounds.Height - 2; e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, width, height)); } e.Graphics.DrawRectangle(new Pen(Color.Gray), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { if (!UseAlternatingColors) base.OnDrawItem(e); else e.Item.BackColor = e.ItemIndex % 2 == 0 ? OddRowColor : EvenRowColor; e.DrawDefault = true; }
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); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { float fillPercent = 0; Color highlightColor = Color.White; if (e.Item is MaterialListViewItem) { MaterialListViewItem mlvi = e.Item as MaterialListViewItem; fillPercent = mlvi.fillPercent; highlightColor = mlvi.highlightColor; } //We draw the current line of items (= item with subitems) on a temp bitmap, then draw the bitmap at once. This is to reduce flickering. var b = new Bitmap(e.Item.Bounds.Width, e.Item.Bounds.Height); var g = Graphics.FromImage(b); //always draw default background int divideSpot = (int)((fillPercent * e.Bounds.Size.Width) / 100); //The spot where the progress splits into background color Rectangle firstRect = e.Bounds; //Set the rectnagle of where firstRect.Width = divideSpot; //the progress is drawn g.FillRectangle(new SolidBrush(e.Item.BackColor), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); //Draw the item's normal background g.FillRectangle(new SolidBrush(highlightColor), new Rectangle(new Point(e.Bounds.X, 0), firstRect.Size)); //Fill with highlight if (e.State.HasFlag(ListViewItemStates.Selected)) { //selected background g.FillRectangle(SkinManager.GetFlatButtonPressedBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } else if (e.Bounds.Contains(MouseLocation) && MouseState == MouseState.HOVER) { //hover background g.FillRectangle(SkinManager.GetFlatButtonHoverBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } //Draw separator g.DrawLine(new Pen(SkinManager.GetDividersColor()), e.Bounds.Left, 0, e.Bounds.Right, 0); foreach (ListViewItem.ListViewSubItem subItem in e.Item.SubItems) { //Draw text g.DrawString(subItem.Text, SkinManager.ROBOTO_MEDIUM_10, SkinManager.GetPrimaryTextBrush(), new Rectangle(subItem.Bounds.Location.X + ITEM_PADDING, ITEM_PADDING, subItem.Bounds.Width - 2 * ITEM_PADDING, subItem.Bounds.Height - 2 * ITEM_PADDING), getStringFormat()); } e.Graphics.DrawImage((Image) b.Clone(), e.Item.Bounds.Location); g.Dispose(); b.Dispose(); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { // Update alternating row colours. if ((e.ItemIndex + 1) % 2 == 0) { e.Item.BackColor = AlternatingRowColour; } else { e.Item.BackColor = DefaultRowColour; } e.DrawDefault = true; base.OnDrawItem(e); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { base.FullRowSelect = _FullRowSelect; if ( !this.ContainsFocus && !_HideSelection ) { ListViewItemStates status = e.Item.Selected ? ListViewItemStates.Selected : e.State; base.OnDrawItem(new DrawListViewItemEventArgs(e.Graphics, e.Item, e.Bounds, e.ItemIndex, status)); } else { base.OnDrawItem(e); } }
public static void DrawListItems(object sender, DrawListViewItemEventArgs e) { Rectangle itemRect = new Rectangle(e.Bounds.X + 5, e.Bounds.Y, e.Bounds.Width - 10, e.Bounds.Height - 1); SolidBrush selectedBackground = new SolidBrush(Color.FromArgb(100, 12, 123, 204)); Pen selectedStroke = new Pen(Color.FromArgb(12, 123, 204)); e.DrawDefault = true; if (e.Item.Selected) { e.Graphics.FillRectangle(selectedBackground, itemRect); e.Graphics.DrawRectangle(selectedStroke, itemRect); } }
protected override void OnDrawItem(DrawListViewItemEventArgs eventArgs) { if (eventArgs.State != 0) { using (var brush = new LinearGradientBrush( eventArgs.Bounds, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.Horizontal)) { // Draw the background for a selected item. eventArgs.Graphics.FillRectangle(brush, eventArgs.Bounds); var highlightBrush = new SolidBrush(SystemColors.Highlight); var iconRect = eventArgs.Item.GetBounds(ItemBoundsPortion.Icon); var iconsSpacerRect = GetIconsSpacerBounds(eventArgs.Item); // Draw selection rectangle for an item if item is selected. if (eventArgs.Item.Selected) { var selectRect = new Rectangle(eventArgs.Bounds.X, eventArgs.Bounds.Y, iconsSpacerRect.X - eventArgs.Bounds.X, eventArgs.Bounds.Height); if (selectRect.Width != 0) eventArgs.Graphics.FillRectangle(highlightBrush, selectRect); selectRect = new Rectangle(iconsSpacerRect.X + iconsSpacerRect.Width, eventArgs.Bounds.Y, eventArgs.Bounds.Width - iconsSpacerRect.X - iconsSpacerRect.Width, eventArgs.Bounds.Height); if (selectRect.Width != 0) eventArgs.Graphics.FillRectangle(highlightBrush, selectRect); } // Draw focus rectangle for an item if item is focused. if (eventArgs.Item.Focused) ControlPaint.DrawFocusRectangle(eventArgs.Graphics, eventArgs.Bounds); // Draw the image for an item if there is one. if (eventArgs.Item.ImageList != null) { var itemImage = eventArgs.Item.ImageList.Images[eventArgs.Item.ImageIndex]; var sourceRect = new Rectangle(0, 0, itemImage.Width, itemImage.Height); var destinationRect = new Rectangle(iconRect.Location, sourceRect.Size); if ((iconsSpacerRect.Width - (iconRect.X - iconsSpacerRect.X)) < destinationRect.Width) { destinationRect.Width = iconsSpacerRect.Width - (iconRect.X - iconsSpacerRect.X); sourceRect.Width = iconsSpacerRect.Width - (iconRect.X - iconsSpacerRect.X); } eventArgs.Graphics.DrawImage(itemImage, destinationRect, sourceRect, GraphicsUnit.Pixel); } var labelBounds = eventArgs.Item.GetBounds(ItemBoundsPortion.Label); var textRect = new Rectangle(labelBounds.X, eventArgs.Bounds.Y, labelBounds.Width, eventArgs.Bounds.Height); TextRenderer.DrawText(eventArgs.Graphics, eventArgs.Item.Text, eventArgs.Item.Font, textRect, eventArgs.Item.Selected ? SystemColors.HighlightText : SystemColors.WindowText, GetTextFormatFlags(Columns[0]) | TextFormatFlags.EndEllipsis); } } base.OnDrawItem(eventArgs); }
void PEListView_DrawItem(object sender, System.Windows.Forms.DrawListViewItemEventArgs e) { var item = e.Item as PEListViewItem; var bounds = item.Bounds; var g = e.Graphics; e.DrawBackground(); bool selected = SelectedItems.Contains(item); Color itemColor = BackColor; if (selected) { itemColor = Color.LightSkyBlue; } using (var highlightBrush = new SolidBrush(Color.FromArgb(200, itemColor))) { var drawBound = bounds; g.FillRectangle(highlightBrush, drawBound); } if (selected) { var drawBound = bounds; drawBound.Width -= 4; drawBound.Height -= 4; drawBound.X += 2; drawBound.Y += 1; using (Pen p = new Pen(Color.FromArgb(100, Color.SteelBlue), 1.5f)) { g.DrawRectangle(p, drawBound); } } if (item.ParentItem == null) { TextRenderer.DrawText(g, item.Text, this.Font, bounds, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsClipping); } }
private void HiddenWindowsListView_DrawItem(object sender, DrawListViewItemEventArgs e) { WindowInfo currentItem = (e.Item as WindowListViewItem).Window; switch (this.View) { case View.LargeIcon: e.DrawDefault = false; e.DrawBackground(); Rectangle itemBounds = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Width, 65)); //if (e.Item.Selected) // e.Graphics.FillRectangle(SystemColors.Highlight.ToBrush(), e.Bounds); Rectangle iconBounds = e.Graphics.AddImage(e.Bounds, currentItem.ApplicationIcon, null, (e.Item.Selected) ? 16 : 18); e.Graphics.AddImage(e.Bounds, (currentItem.IsPasswordProtected) ? ActionResource.lockwindow_small : ActionResource.unlockwindow_small, ImageOverlayPosition.TopLeft); if (currentItem.IsPinned) e.Graphics.AddImage(e.Bounds, ActionResource.tack_small, ImageOverlayPosition.TopRight); //e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter); Rectangle rec = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Height - 4); TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Item.Font, rec, e.Item.ForeColor, TextFormatFlags.Bottom | TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.ExpandTabs | TextFormatFlags.SingleLine); //e.DrawFocusRectangle(); break; default: e.DrawDefault = true; break; } if ((bool) e.Item.SubItems[1].Tag != currentItem.IsPasswordProtected) { e.Item.SubItems[1].Tag = currentItem.IsPasswordProtected; e.Item.SubItems[1].Text = currentItem.IsPasswordProtected ? "Yes" : "No"; } if ((bool) e.Item.SubItems[2].Tag != currentItem.IsPinned) { e.Item.SubItems[2].Tag = currentItem.IsPinned; e.Item.SubItems[2].Text = currentItem.IsPinned ? "Yes" : "No"; } }
private void RssListView_DrawItem(object sender, DrawListViewItemEventArgs e) { if ((e.State & ListViewItemStates.Selected) != 0) { // Draw the background and focus rectangle for a selected item. // e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds); e.DrawFocusRectangle(); } else { // Draw the background for an unselected item. /*using (LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.Orange, Color.Maroon, LinearGradientMode.Horizontal)) { e.Graphics.FillRectangle(brush, e.Bounds); }*/ } }
private void LvGroupsDrawItem(object sender, DrawListViewItemEventArgs e) { bool isSeparator = e.Item.Text == "-"; Brush brush; if (e.Item == _itemAtCursor && !e.Item.Selected) { brush = Brushes.Gainsboro; } else { brush = !e.Item.Selected || isSeparator ? Brushes.White : Brushes.Silver; } e.Graphics.FillRectangle(brush, e.Bounds); if (!isSeparator) { Rectangle rect = new Rectangle(e.Item.Bounds.X + 32, e.Item.Bounds.Y + 7, e.Item.Bounds.Width - 32, e.Item.Bounds.Height - 7); Font font = new Font(Font, e.Item.Selected ? FontStyle.Bold : FontStyle.Regular); e.Graphics.DrawString(e.Item.Text, font, Brushes.Black, rect); e.Graphics.DrawImage(SmallImageList.Images[e.Item.ImageIndex], e.Item.Bounds.Location); } else { const int margin = 6; const float lineHeight = 1f; Color penColor = Color.Gray; Pen pen = new Pen(penColor, lineHeight); pen.StartCap = pen.EndCap = LineCap.Flat; //e.Graphics.SmoothingMode = SmoothingMode.HighQuality; Point ptStart = new Point( e.Item.Bounds.X + margin, (int)(e.Item.Bounds.Top + e.Item.Bounds.Height / 2 - lineHeight / 2) + 1); Point ptEnd = new Point( ptStart.X + (ClientRectangle.Width - margin * 2), ptStart.Y); e.Graphics.DrawLine(pen, ptStart, ptEnd); } }
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); string previewStr = char.ConvertFromUtf32(LastChar); var sf = new StringFormat(StringFormatFlags.NoFontFallback); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; var font = new Font(e.Item.Text, 72f, FontStyle.Regular, GraphicsUnit.Pixel); var smallFont = new Font(e.Item.Text, 12f, FontStyle.Regular, GraphicsUnit.Pixel); e.Graphics.DrawString(previewStr, font, SystemBrushes.WindowText, e.Bounds, sf); RectangleF labelRect = new RectangleF(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - 24), e.Bounds.Width, 24); e.Graphics.DrawString(e.Item.Text, smallFont, SystemBrushes.WindowText, labelRect, sf); }
private void lvIcons_DrawItem(object sender, DrawListViewItemEventArgs e) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if ((e.State & ListViewItemStates.Hot) != 0 && (e.State & ListViewItemStates.Selected) == 0) { this._ItemHoverRenderer.DrawBackground(e.Graphics, e.Bounds); } else if ((e.State & ListViewItemStates.Hot) != 0 && (e.State & ListViewItemStates.Selected) != 0) { this._Selectedx2Renderer.DrawBackground(e.Graphics, e.Bounds); } else if ((e.State & ListViewItemStates.Selected) != 0) { this._ItemSelectedRenderer.DrawBackground(e.Graphics, e.Bounds); } else { e.DrawBackground(); } var ico = _Icons[(int)e.Item.Tag].Icon; if (ico.Width <= 48) { e.Graphics.DrawIcon(_Icons[(int)e.Item.Tag].Icon, e.Bounds.X + (e.Bounds.Width - ico.Width) / 2, e.Bounds.Y + (e.Bounds.Height - ico.Height) / 2 - 5); } e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordEllipsis); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { Rectangle r = e.Bounds; if (r.Width > this.ClientSize.Width) r.Width = this.ClientSize.Width; Graphics g = e.Graphics; r.X += 1; //3 r.Width -= 2; int offset = 0; bool isSelected = e.Item == m_hoverItem; Brush backBrush = isSelected ? SystemBrushes.Highlight : new SolidBrush(this.BackColor); g.FillRectangle(backBrush, r); if (this.CheckBoxes) { CheckBoxState boxState = e.Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(g, new Point(r.X + 3, r.Y + (r.Height / 2) - 6), boxState); offset = CheckBoxRenderer.GetGlyphSize(g, boxState).Width + 6; r.X += offset; r.Width -= offset; } int imgFlags = ILD_TRANSPARENT; if (isSelected) imgFlags |= ILD_BLEND25; int imgIndex = this.SmallImageList.Images.IndexOfKey(e.Item.ImageKey); bool result = ImageList_Draw(this.SmallImageList.Handle, imgIndex, g.GetHdc(), r.X, r.Y, imgFlags); g.ReleaseHdc(); offset = this.SmallImageList.ImageSize.Width; r.X += offset; r.Width -= offset; string txt = e.Item.SubItems[0].Text; Color backColor = isSelected ? SystemColors.Highlight : Color.Transparent; Color foreColor = isSelected ? SystemColors.HighlightText : this.ForeColor; TextFormatFlags textFlags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.SingleLine; TextRenderer.DrawText(g, txt, this.Font, r, foreColor, backColor, textFlags); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { //We draw the current line of items (= item with subitems) on a temp bitmap, then draw the bitmap at once. This is to reduce flickering. var b = new Bitmap(e.Item.Bounds.Width, e.Item.Bounds.Height); var g = Graphics.FromImage(b); //always draw default background g.FillRectangle(new SolidBrush(SkinManager.GetApplicationBackgroundColor()), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); if (e.State.HasFlag(ListViewItemStates.Selected)) { //selected background g.FillRectangle(SkinManager.GetFlatButtonPressedBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } else if (e.Bounds.Contains(MouseLocation) && MouseState == MouseState.HOVER) { //hover background g.FillRectangle(SkinManager.GetFlatButtonHoverBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } //Draw separator g.DrawLine(new Pen(SkinManager.GetDividersColor()), e.Bounds.Left, 0, e.Bounds.Right, 0); foreach (ListViewItem.ListViewSubItem subItem in e.Item.SubItems) { //Draw text g.DrawString(subItem.Text, SkinManager.ROBOTO_MEDIUM_10, SkinManager.GetPrimaryTextBrush(), new Rectangle(subItem.Bounds.Location.X + ITEM_PADDING, ITEM_PADDING, subItem.Bounds.Width - 2 * ITEM_PADDING, subItem.Bounds.Height - 2 * ITEM_PADDING), getStringFormat()); } e.Graphics.DrawImage((Image) b.Clone(), e.Item.Bounds.Location); g.Dispose(); b.Dispose(); }
private void drawitem(object sender, DrawListViewItemEventArgs e) { int i = int.Parse(e.Item.Text.ToString()); Bitmap bmp; char c = (char)i; if ((int)treeView.SelectedNode.Parent.Tag == 1) // Unicode bmp = UnicodeFonts.Fonts[(int)treeView.SelectedNode.Tag].Chars[i].GetImage(); else bmp = (Bitmap)e.Item.Tag; if (listView1.SelectedItems.Contains(e.Item)) e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); string symbol; if (i < 256) // Даже для юникода первые 256 символов отображаем в кодировки win-1251 (т.к. клиент часто выводит ASCII текст юникодными шрифтами) symbol = System.Text.ASCIIEncoding.GetEncoding(1251).GetString(new byte[] { (byte)i }); else // Для всех остальных юникодных символов отображаем юникодные символы symbol = c.ToString(); e.Graphics.DrawString(symbol, Fonts.DefaultFont, Brushes.Gray, e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Y + e.Bounds.Height / 2); if (bmp != null) { int width = bmp.Width; int height = bmp.Height; if (width > e.Bounds.Width) width = e.Bounds.Width - 2; if (height > e.Bounds.Height) height = e.Bounds.Height - 2; e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, width, height)); } e.Graphics.DrawRectangle(new Pen(Color.Gray), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); }
private void _ListAccounts_DrawItem(object sender, DrawListViewItemEventArgs e) { AccountListItem item = e.Item as AccountListItem; Bitmap image = item.Account.Type == AccountTypes.Regular ? _iconStandard : _iconApps; int elementState = 1; if ((e.State & ListViewItemStates.Selected) != 0) { if ((e.State & ListViewItemStates.Focused) != 0) { elementState = 3; // Selected } else { elementState = 5; // SelectedNotFocus; } } else if ((e.State & ListViewItemStates.Hot) != 0) { elementState = 2; // Hot } if (elementState > 1) { VisualStyleElement element = VisualStyleElement.CreateElement("Explorer::ListView", 1, elementState); VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e.Graphics, item.Bounds); } PaintAccountGlyph(e.Graphics, e.Item.Bounds, item.Account); //int tileWidth = _userFrame.Width; //int tileHeight = (int)(((float)tileWidth / (float)image.Width) * image.Height); //RectangleF clipRect = new RectangleF(item.Bounds.Left + 14, item.Bounds.Top + 13, _userFrame.Width - 30, _userFrame.Height - 30); //// //e.Graphics.SetClip(clipRect); //e.Graphics.DrawImage(image, item.Bounds.Left, item.Bounds.Top + 10, tileWidth, tileHeight); //e.Graphics.ResetClip(); //e.Graphics.DrawImage(_userFrame, new Rectangle(item.Bounds.Left, item.Bounds.Top, _userFrame.Width, _userFrame.Height)); //Point addressPoint = new Point(item.Bounds.Left + _userFrame.Width, item.Bounds.Top); //Rectangle addressRect = new Rectangle(addressPoint.X, addressPoint.Y, item.Bounds.Width - _userFrame.Width, item.Bounds.Height); //Rectangle textExtent = _rendererListSmall.GetTextExtent(e.Graphics, addressRect, item.Account.FullAddress, TextFormatFlags.Left); //int center = (_userFrame.Height - textExtent.Height) / 2; //if (item.Account.Default) { // Rectangle defaultExtent = _rendererListSmall.GetTextExtent(e.Graphics, addressRect, Locale.Current.JumpList.DefaultAccount, TextFormatFlags.Left); // center -= (defaultExtent.Height / 2) + 4; // 4 is the additional padding we're adding //} //addressRect.Offset(0, center); //_rendererListSmall.DrawText(e.Graphics, addressRect, item.Account.FullAddress, false, TextFormatFlags.Left); //if (item.Account.Default) { // addressRect.Offset(0, textExtent.Height + 4); // _rendererListSmall.DrawText(e.Graphics, addressRect, Locale.Current.JumpList.DefaultAccount, true, TextFormatFlags.Left); //} }
// listViewToSync_DrawItem is not currently used since listViewToSync is not ownerDraw // this is maintained for future extension private void listViewToSync_DrawItem(object sender, DrawListViewItemEventArgs e) { Rectangle r=listViewToSync.GetItemRect(e.ItemIndex, ItemBoundsPortion.Icon); r.X = r.X + (r.Width - ThumbnailSize) / 2; r.Y = r.Y + (r.Height - ThumbnailSize) / 2; r.Width = ThumbnailSize; r.Height = ThumbnailSize; e.Graphics.DrawImage(e.Item.ImageList.Images[e.Item.ImageIndex], r); if (listViewToSync.View != View.Details) { StringFormat fmt = new StringFormat(); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.FormatFlags = StringFormatFlags.LineLimit; fmt.Alignment = StringAlignment.Center; Rectangle r2 = e.Item.Bounds; r2.Y = r.Y + r.Height + 1; r2.Height = e.Item.Bounds.Bottom - r2.Y; e.Graphics.DrawString(e.Item.Text, listViewToSync.Font, new SolidBrush(e.Item.ForeColor), r2, fmt); } }
void HistoryListView_DrawItem(object sender, DrawListViewItemEventArgs e) { if (e.ItemIndex < 0) return; if (this.View == View.Tile) { // draw the background and focus rectangle for selected and non-selected states if (this.SelectedIndices.Contains(e.ItemIndex)) { e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds); ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } else { e.DrawBackground(); } // draw icon PastNotification pn = (PastNotification)e.Item.Tag; int newX = e.Bounds.Left; if (pn != null) { System.Drawing.Image img = PastNotificationManager.GetImage(pn); using (img) { if (img != null) { int x = e.Bounds.Left + 1; int y = e.Bounds.Top + 1; e.Graphics.DrawImage(img, x, y); newX = e.Bounds.Left + img.Width + this.Margin.Right; } } } // draw main text System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, e.Bounds.Top, e.Bounds.Right - newX, e.Item.Font.Height); System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip; System.Drawing.SolidBrush foreBrush = new System.Drawing.SolidBrush(e.Item.ForeColor); string text = e.Item.Text.Replace("\r", " - "); using (foreBrush) { e.Graphics.DrawString(text, e.Item.Font, foreBrush, rect, sf); } // draw subitems System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()); System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor); using (subBrush) { for (int i = 1; i < this.Columns.Count; i++) { if (i < e.Item.SubItems.Count) { text = e.Item.SubItems[i].Text.Replace("\r", " - "); rect.Offset(0, e.Item.Font.Height); e.Graphics.DrawString(text, e.Item.Font, subBrush, rect, sf); } } } } else { // DO NOT call e.DrawDefault or the DrawSubItem event will not be fired //e.DrawDefault = true; } }
private void drawitem(object sender, DrawListViewItemEventArgs e) { int i = (int)listView1.Items[e.ItemIndex].Tag; bool patched; Bitmap bmp = Art.GetLand(i, out patched); if (bmp != null) { if (listView1.SelectedItems.Contains(e.Item)) e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else if (patched) e.Graphics.FillRectangle(Brushes.LightCoral, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else e.Graphics.FillRectangle(Brushes.White, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); int width = bmp.Width; int height = bmp.Height; if (width > e.Bounds.Width) width = e.Bounds.Width - 2; if (height > e.Bounds.Height) height = e.Bounds.Height - 2; e.Graphics.DrawImage(bmp, e.Bounds.X + 1, e.Bounds.Y + 1, new Rectangle(0, 0, e.Bounds.Width - 1, e.Bounds.Height - 1), GraphicsUnit.Pixel); if (listView1.SelectedItems.Contains(e.Item)) e.DrawFocusRectangle(); else e.Graphics.DrawRectangle(Pens.Gray, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); } }
private void listView_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawBackground(); e.DrawText(); }
private void lsvMods_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawDefault = true; if (e.Item.Index != -1) { if (lsvMods.Enabled) e.DrawBackground(); if ((e.State & ListViewItemStates.Selected) > 0) { Color c = Color.FromKnownColor(KnownColor.Highlight); Brush brush = new LinearGradientBrush(e.Bounds, c, c, LinearGradientMode.Horizontal); e.Graphics.FillRectangle(brush, e.Bounds); } } }
private void drawitem(object sender, DrawListViewItemEventArgs e) { int i = (int)e.Item.Tag; if (i == -1) { if (e.Item.Selected) e.Graphics.FillRectangle(BrushLightBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else e.Graphics.DrawRectangle(PenGray, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); e.Graphics.FillRectangle(BrushRed, e.Bounds.X + 5, e.Bounds.Y + 5, e.Bounds.Width - 10, e.Bounds.Height - 10); return; } bool patched; Bitmap bmp = Art.GetStatic(i, out patched); if (bmp != null) { if (e.Item.Selected) e.Graphics.FillRectangle(BrushLightBlue, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else if (patched) e.Graphics.FillRectangle(BrushLightCoral, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); else e.Graphics.FillRectangle(BrushWhite, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); if (Options.ArtItemClip) { e.Graphics.DrawImage(bmp, e.Bounds.X + 1, e.Bounds.Y + 1, new Rectangle(0, 0, e.Bounds.Width - 1, e.Bounds.Height - 1), GraphicsUnit.Pixel); } else { int width = bmp.Width; int height = bmp.Height; if (width > e.Bounds.Width) { width = e.Bounds.Width; height = e.Bounds.Height * bmp.Height / bmp.Width; } if (height > e.Bounds.Height) { height = e.Bounds.Height; width = e.Bounds.Width * bmp.Width / bmp.Height; } e.Graphics.DrawImage(bmp, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, width, height)); } if (!e.Item.Selected) e.Graphics.DrawRectangle(PenGray, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); } }
/// <summary> /// Owner draw the item /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawListViewItemEventArgs e) { if (this.View == View.Details) e.DrawDefault = false; else { if (this.ItemRenderer == null) e.DrawDefault = true; else { Object row = ((OLVListItem)e.Item).RowObject; e.DrawDefault = !this.ItemRenderer.RenderItem(e, e.Graphics, e.Bounds, row); } } if (e.DrawDefault) base.OnDrawItem(e); }
private void lvTaskList_DrawItem(object sender, DrawListViewItemEventArgs e) { //Get the task associated with the list view item WlbScheduledTask task = TaskFromItem(e.Item); //Set the row color based on the Opt Mode Color color = GetTaskOptMode(task) == WlbPoolPerformanceMode.MaximizePerformance ? COLOR_MAX_PERFORMANCE : COLOR_MAX_DENSITY; if (!task.Enabled) { color = COLOR_DISABLED_TASK; } // Fill the full width of the control, not just to the end of the column headers. Rectangle rect = e.Bounds; int i = 0; foreach (ColumnHeader col in lvTaskList.Columns) { i += col.Width; } // Fill from the right of the rightmost item to the end of the control rect.Width = Math.Max(i, lvTaskList.ClientSize.Width); rect.X = i; if (e.Item.Selected) { using (SolidBrush brush = new SolidBrush(SystemColors.Highlight)) e.Graphics.FillRectangle(brush, rect); } else { Rectangle topRect = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height / 2); Rectangle botRect = new Rectangle(rect.X, rect.Y + topRect.Height, rect.Width, rect.Height / 2); if (e.ItemIndex == 0 || (e.ItemIndex > 0 && lvTaskList.Items[e.ItemIndex - 1].SubItems[2].Text != e.Item.SubItems[2].Text)) { using (LinearGradientBrush brush = new LinearGradientBrush(topRect, COLOR_NEW_DAY, ControlPaint.LightLight(color), 90f)) // SystemBrushes.Highlight; { e.Graphics.FillRectangle(brush, topRect); } } else { using (LinearGradientBrush brush = new LinearGradientBrush(topRect, color, ControlPaint.LightLight(color), 90f)) // SystemBrushes.Highlight; { e.Graphics.FillRectangle(brush, topRect); } } using (LinearGradientBrush brush = new LinearGradientBrush(botRect, ControlPaint.LightLight(color), color, 90f)) // SystemBrushes.Highlight; { e.Graphics.FillRectangle(brush, botRect); } } }
protected virtual void OnDrawItem(DrawListViewItemEventArgs e) { throw null; }