protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) { 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(CellBorderFocused.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } } // Draw normal text for a subitem with a nonnegative // or nonnumerical value. e.DrawText(flags); } break; } }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { switch (DrawMode) { case drawMode.Default: base.OnDrawColumnHeader(e); break; case drawMode.Stylish: base.OnDrawColumnHeader(e); if (!HideHeader) { int internalWidth = e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width); int internalHeight = (e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width)); Graphics g = e.Graphics; GraphicsPath BG = CreateRoundRect(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, internalWidth - 3, internalHeight - 3, radius); g.SmoothingMode = Smoothing; g.TextRenderingHint = TextRendering; SizeF fs = g.MeasureString(e.Header.Text, HeaderFont, e.Bounds.Width).ToSize(); 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; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } if (rounding) { if (ShowBorder) { g.FillPath(ColumnHeader.GetBrush(new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, internalWidth - 3, internalHeight - 3)), BG); g.DrawPath(HeaderBorder.GetPen(), BG); //g.DrawRectangle(HeaderBorder.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } else { BG = CreateRoundRect(e.Bounds.X, e.Bounds.Y, internalWidth, internalHeight, radius); g.FillPath(ColumnHeader.GetBrush(new Rectangle(e.Bounds.X, e.Bounds.Y, internalWidth, internalHeight)), BG); } } else { g.FillRectangle(ColumnHeader.GetBrush(e.Bounds), e.Bounds); if (ShowBorder) { g.DrawRectangle(HeaderBorder.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } } if (ShowHeaderLine) { foreach (ColumnHeader items in Columns) { //g.DrawRectangle(new Pen(LineColor,lineHeight), new Rectangle(e.Bounds.X, e.Bounds.Y + (int)fs.Height + (int)(fs.Height / 4), items.Width, LineHeight)); g.DrawLine(new Pen(LineColor, lineHeight), new Point(e.Bounds.X, e.Bounds.Y + (int)fs.Height /*+ (int)(fs.Height / 10)*/), new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (int)fs.Height /*+ (int)(fs.Height / 10)*/)); } } switch (HeaderAlignment) { case headerAlignment.Left: g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), e.Bounds, sf); break; case headerAlignment.Center: foreach (ColumnHeader items in Columns) { g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), new Rectangle(e.Bounds.X + (e.Bounds.Width / 2 - (int)(fs.Width / 2)), e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), sf); } break; case headerAlignment.Right: foreach (ColumnHeader items in Columns) { g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), new Rectangle(e.Bounds.X + (e.Bounds.Width - (int)fs.Width), e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), sf); } break; default: throw new ArgumentOutOfRangeException(); } } } if (!DesignMode) { GC.Collect(); } return; } }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { switch (DrawMode) { case drawMode.Default: base.OnDrawItem(e); break; case drawMode.Stylish: base.OnDrawItem(e); if ((e.State & ListViewItemStates.Selected) != 0) { // Draw the background and focus rectangle for a selected item. e.Graphics.FillRectangle(FillFocused.GetBrush(e.Bounds), e.Bounds); if (SurrondBorder) { e.Graphics.DrawRectangle(CellBorderFocused.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } e.DrawFocusRectangle(); } else { e.Graphics.FillRectangle(FillUnfocused.GetBrush(e.Bounds), e.Bounds); if (SurrondBorder) { e.Graphics.DrawRectangle(CellBorderUnFocused.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } } // Draw the item text for views other than the Details view. if (View != View.Details) { e.DrawText(); } break; } }