private void ListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // We draw the current line of items (= item with sub items) on a temp bitmap, then draw the bitmap at once. This is to reduce flickering. Bitmap _bitmap = new Bitmap(e.Item.Bounds.Width, e.Item.Bounds.Height); Graphics _graphics = Graphics.FromImage(_bitmap); if (e.ItemState.HasFlag(ListViewItemStates.Selected)) { _graphics.FillRectangle(new SolidBrush(_itemSelected), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } else if (e.Bounds.Contains(LastPosition) && (MouseState == MouseStates.Hover) && _hoverItem) { _graphics.FillRectangle(new SolidBrush(_itemHover), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } else { _graphics.FillRectangle(new SolidBrush(e.Item.BackColor), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size)); } // Draw separator // graphics.DrawLine(new Pen(Color.Red), e.Bounds.Left, 0, e.Bounds.Right, 0); foreach (ListViewItem.ListViewSubItem subItem in e.Item.SubItems) { // Draw text _graphics.DrawString(subItem.Text, Font, new SolidBrush(Color.Black), new Rectangle(subItem.Bounds.X + _itemPadding, _itemPadding, subItem.Bounds.Width - (2 * _itemPadding), subItem.Bounds.Height - (2 * _itemPadding)), GetStringFormat()); } // Draw the item text for views other than the Details view if (_listView.View != View.Details) { e.DrawText(); } TextFormatFlags _textFormatFlags = TextFormatFlags.Left; StringFormat _stringFormat = new StringFormat(); // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. switch (e.Header.TextAlign) { case HorizontalAlignment.Center: { _stringFormat.Alignment = StringAlignment.Center; _textFormatFlags = TextFormatFlags.HorizontalCenter; break; } case HorizontalAlignment.Right: { _stringFormat.Alignment = StringAlignment.Far; _textFormatFlags = TextFormatFlags.Right; break; } case HorizontalAlignment.Left: { break; } default: { throw new ArgumentOutOfRangeException(); } } // Draw the text and background for a sub item with a // negative value. double _subItemValue; if ((e.ColumnIndex > 0) && double.TryParse(e.SubItem.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out _subItemValue) && (_subItemValue < 0)) { // Unless the item is selected, draw the standard // background to make it stand out from the gradient. if ((e.ItemState & ListViewItemStates.Selected) == 0) { e.DrawBackground(); } // Draw the sub item text in red to highlight it. _graphics.DrawString(e.SubItem.Text, Font, Brushes.Red, e.Bounds, _stringFormat); return; } e.Graphics.DrawImage((Image)_bitmap.Clone(), new Point(0, e.Item.Bounds.Location.Y)); // Draw normal text for a sub item with a non negative // or non numerical value. e.DrawText(_textFormatFlags); _graphics.Dispose(); _bitmap.Dispose(); }
private void lvwSecurityGroup_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { if (e.Item.Selected) { e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), e.Bounds); e.Graphics.DrawString(e.SubItem.Text, new Font("Tahoma", 8), new SolidBrush(Color.Black), e.Bounds); } else { e.DrawBackground(); e.DrawText(); } }
private void propertyListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawBackground(); e.DrawText(); }
private void lvPlugins_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var plugin = (XtbPlugin)e.Item.Tag; if (e.ColumnIndex == 2 && e.SubItem.Text.Length > 0) { if (e.Item.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); } var dValue = decimal.Parse(e.SubItem.Text); if (dValue > 0) { var sourceBmp = new Bitmap(ilImages.Images[0]); Rectangle srcRect = new Rectangle(0, 0, Convert.ToInt32(Math.Truncate(dValue / 5 * 80)), 16); Bitmap cropped = sourceBmp.Clone(srcRect, sourceBmp.PixelFormat); e.Graphics.DrawImage(cropped, new Point(e.Bounds.X, e.Bounds.Y)); e.Graphics.DrawString($"({plugin.TotalFeedbackRating})", e.Item.Font, new SolidBrush(e.Item.ForeColor), new PointF(e.Bounds.X + 80, e.Bounds.Y + 2)); } } else if (e.ColumnIndex == 0) { e.DrawDefault = true; } else { // Draw the standard header background. e.DrawBackground(); if (e.Item.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); } if (e.ColumnIndex == 1 && plugin.FirstReleaseDate > DateTime.Now.AddMonths(-1) && (plugin.Action == PackageInstallAction.Install || plugin.Action == PackageInstallAction.Unavailable)) { //add a 2 pixel buffer the match default behavior Rectangle rec = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 20, e.Bounds.Height - 4); TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine; //If a different tabstop than the default is needed, will have to p/invoke DrawTextEx from win32. TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.Item.ListView.Font, rec, e.Item.Selected ? Color.White : e.Item.ForeColor, flags); e.Graphics.DrawImage(iiNotif.Images[3], e.Bounds.X + e.Bounds.Width - 20, e.Bounds.Y); } else { //add a 2 pixel buffer the match default behavior Rectangle rec = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Height - 4); TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine; //If a different tabstop than the default is needed, will have to p/invoke DrawTextEx from win32. TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.Item.ListView.Font, rec, e.Item.Selected ? Color.White : e.Item.ForeColor, flags); } } }
private void listView_syncStatus_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawBackground(); //e.DrawFocusRectangle(); e.DrawText(); }
//*********************************************************************************** private void this_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { if (!data.ContainsKey(e.SubItem)) { return; } DataItem dataitem = data[e.SubItem]; e.DrawBackground(); if (e.Item.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); } if (dataitem.type == DataType.Text) { e.Graphics.DrawString(dataitem.text, e.SubItem.Font, (e.Item.Selected) ? SystemBrushes.HighlightText : SystemBrushes.WindowText, e.Bounds.Left + 1, e.Bounds.Top + 1); } if (dataitem.type == DataType.ImageIndex_Text) { if (SmallImageList != null) { if (dataitem.imageIndex > -1 && dataitem.imageIndex < SmallImageList.Images.Count) { Image image = SmallImageList.Images[dataitem.imageIndex]; e.Graphics.DrawImage(image, new Point(e.Bounds.Left + 1, e.Bounds.Top + 1)); } } e.Graphics.DrawString(dataitem.text, e.SubItem.Font, (e.Item.Selected) ? SystemBrushes.HighlightText : SystemBrushes.WindowText, e.Bounds.Left + 16, e.Bounds.Top + 1); } if (dataitem.type == DataType.Image_Text) { if (dataitem.image != null) { e.Graphics.DrawImage(dataitem.image, new Point(e.Bounds.Left + 1, e.Bounds.Top + 1)); } e.Graphics.DrawString(dataitem.text, e.SubItem.Font, (e.Item.Selected) ? SystemBrushes.HighlightText : SystemBrushes.WindowText, e.Bounds.Left + 16, e.Bounds.Top + 1); } if (dataitem.type == DataType.Progress) { Rectangle rect = e.Bounds; rect.Y += 1; rect.Height -= 3; rect.Width -= 2; Rectangle rectProgress = rect; rectProgress.Width = (int)rect.Width * (int)dataitem.progress / 100; e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), rect); e.Graphics.FillRectangle( new LinearGradientBrush( new Point(e.Bounds.Left + 1, e.Bounds.Top + 1), new Point(e.Bounds.Left + 1, e.Bounds.Bottom - 1), Color.Lime, Color.LimeGreen), rectProgress); e.Graphics.DrawRectangle(new Pen(Color.Black), rect); StringFormat strFormat = new StringFormat(); strFormat.Alignment = StringAlignment.Center; e.Graphics.DrawString(String.Format("{0:0.000}%", dataitem.progress), e.SubItem.Font, SystemBrushes.WindowText, rect.Left + rect.Width / 2, rect.Top, strFormat); } }
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) { Pen cellBorderFocusedBrush = new Pen(CellBorderFocused); switch (DrawMode) { case drawMode.Default: base.OnDrawSubItem(e); break; case drawMode.Stylish: base.OnDrawSubItem(e); Graphics g = e.Graphics; g.SmoothingMode = Smoothing; g.TextRenderingHint = TextRendering; TextFormatFlags flags = TextFormatFlags.Left; using (StringFormat sf = new StringFormat()) { // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; flags = TextFormatFlags.HorizontalCenter; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; flags = TextFormatFlags.Right; break; } // Draw the text and background for a subitem with a // negative value. double subItemValue; if (e.ColumnIndex > 0 && Double.TryParse( e.SubItem.Text, NumberStyles, NumberFormatInfo.CurrentInfo, out subItemValue) && subItemValue < 0) { // Unless the item is selected, draw the standard // background to make it stand out from the gradient. if ((e.ItemState & ListViewItemStates.Selected) == 0) { e.DrawBackground(); } // Draw the subitem text in red to highlight it. g.DrawString(e.SubItem.Text, Font, new SolidBrush(SubTextColor), e.Bounds, sf); return; } if (ShowCellBorder) { foreach (var items in Items) { e.Graphics.DrawRectangle(cellBorderFocusedBrush, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2)); } } // Draw normal text for a subitem with a nonnegative // or nonnumerical value. e.DrawText(flags); } break; } }