/// <summary> /// Occurs during the drawing of an item. /// </summary> /// <param name="e">The event args.</param> protected override void OnDrawItem(DrawItemEventArgs e) { Rectangle outer = e.Bounds; outer.Inflate(1, 1); e.Graphics.FillRectangle(Brushes.White, outer); Brush fontBrush = Brushes.Black; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { Rectangle r = e.Bounds; r.Inflate(-1, -1); e.Graphics.FillRectangle(SymbologyGlobal.HighlightBrush(r, Color.FromArgb(215, 238, 252)), r); Pen p = new Pen(Color.FromArgb(215, 238, 252)); SymbologyGlobal.DrawRoundedRectangle(e.Graphics, p, e.Bounds); p.Dispose(); } string name = Items[e.Index].ToString(); FontFamily ff = new FontFamily(name); Font fnt = new Font("Arial", 10, FontStyle.Regular); if (ff.IsStyleAvailable(FontStyle.Regular)) { fnt = new Font(name, 10, FontStyle.Regular); } else if (ff.IsStyleAvailable(FontStyle.Italic)) { fnt = new Font(name, 10, FontStyle.Italic); } SizeF box = e.Graphics.MeasureString(name, Font); e.Graphics.DrawString(name, Font, fontBrush, e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString("ABC", fnt, fontBrush, e.Bounds.X + box.Width, e.Bounds.Y); }
protected virtual PointF OnInitializeItem(DrawLegendItemArgs e) { if (e.Item.LegendItemVisible == false) { return(e.TopLeft); } UpdateActions(e.Item); PointF topLeft = e.TopLeft; PointF tempTopLeft = topLeft; if (topLeft.Y > ControlRectangle.Bottom) { return(topLeft); // drawing would be below the screen } if (topLeft.Y > ControlRectangle.Top - ItemHeight) { // Draw the item itself // Point tl = new Point((int)topLeft.X, (int)topLeft.Y); var itemBox = new LegendBox(); _legendBoxes.Add(itemBox); itemBox.Item = e.Item; itemBox.Bounds = new Rectangle(0, (int)topLeft.Y, Width, ItemHeight); itemBox.Indent = (int)topLeft.X / _indentation; DrawPlusMinus(e.Graphics, ref tempTopLeft, itemBox); int ih = ItemHeight; if (e.Item.LegendSymbolMode == SymbolMode.Symbol) { Size s = e.Item.GetLegendSymbolSize(); if (s.Height > ih) { tempTopLeft.Y += 3; } } if (e.Item.LegendSymbolMode == SymbolMode.Symbol || e.Item.LegendSymbolMode == SymbolMode.GroupSymbol) { DrawSymbol(e.Graphics, ref tempTopLeft, itemBox); } if (e.Item.LegendSymbolMode == SymbolMode.Checkbox) { DrawCheckBoxes(e.Graphics, ref tempTopLeft, itemBox); } int width = (int)e.Graphics.MeasureString(e.Item.LegendText, Font).Width; int dY = 0; if (e.Item.LegendSymbolMode == SymbolMode.Symbol) { Size s = e.Item.GetLegendSymbolSize(); if (s.Height > ih) { dY = (s.Height - ih) / 2; } tempTopLeft.Y += dY; } tempTopLeft.Y += (ih - Font.Height) / (float)2; itemBox.Textbox = new Rectangle((int)tempTopLeft.X, (int)topLeft.Y + dY, width, ItemHeight); if (itemBox.Item.IsSelected) { _selection.Add(itemBox.Item); Rectangle innerBox = itemBox.Textbox; innerBox.Inflate(-1, -1); using (var b = HighlightBrush(innerBox)) { e.Graphics.FillRectangle(b, innerBox); } SymbologyGlobal.DrawRoundedRectangle(e.Graphics, _highlightBorderPen, itemBox.Textbox); e.Graphics.DrawString(e.Item.LegendText, Font, _selectionFontBrush, tempTopLeft); } else { e.Graphics.DrawString(e.Item.LegendText, Font, Brushes.Black, tempTopLeft); } } int h = ItemHeight; if (e.Item.LegendSymbolMode == SymbolMode.Symbol) { Size s = e.Item.GetLegendSymbolSize(); if (s.Height > h) { h = s.Height + 6; } } topLeft.Y += h; if (e.Item.IsExpanded) { topLeft.X += _indentation; if (e.Item.LegendItems != null) { List <ILegendItem> items = e.Item.LegendItems.ToList(); if (e.Item is IGroup) { items.Reverse(); // reverse layers because of drawing order, don't bother reversing categories. } foreach (var item in items) { var args = new DrawLegendItemArgs(e.Graphics, item, e.ClipRectangle, topLeft); topLeft = OnInitializeItem(args); if (topLeft.Y > ControlRectangle.Bottom) { break; } } } topLeft.X -= _indentation; } return(topLeft); }
/// <summary> /// This supplies the basic drawing for this one element where the graphics object has been transformed /// based on the position of this item. /// </summary> /// <param name="e">A PaintEventArgs that contains the Graphics object needed for drawing.</param> protected virtual void OnDraw(PaintEventArgs e) { //System.Diagnostics.Debug.WriteLine("top: " + this.Top.ToString()); int left = 1; Pen border = Pens.White; Pen innerBorder = Pens.White; Brush fill = Brushes.White; Pen dots = new Pen(Color.Black); bool specialDrawing = false; dots.DashStyle = DashStyle.Dot; if (_isHighlighted && _isSelected == false) { border = new Pen(Color.FromArgb(216, 240, 250)); innerBorder = new Pen(Color.FromArgb(248, 252, 254)); fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(245, 250, 253), Color.FromArgb(232, 245, 253), LinearGradientMode.Vertical); specialDrawing = true; } if (_isSelected && _isHighlighted == false) { border = new Pen(Color.FromArgb(153, 222, 253)); innerBorder = new Pen(Color.FromArgb(231, 245, 253)); fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.Vertical); specialDrawing = true; } if (_isSelected && _isHighlighted) { border = new Pen(Color.FromArgb(182, 230, 251)); innerBorder = new Pen(Color.FromArgb(242, 249, 253)); fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(232, 246, 253), Color.FromArgb(196, 232, 250), LinearGradientMode.Vertical); specialDrawing = true; } e.Graphics.FillRectangle(fill, new Rectangle(1, 1, Width - 2, Height - 2)); SymbologyGlobal.DrawRoundedRectangle(e.Graphics, innerBorder, new Rectangle(2, 2, Width - 4, Height - 4)); SymbologyGlobal.DrawRoundedRectangle(e.Graphics, border, new Rectangle(1, 1, Width - 2, Height - 2)); if (_isOutlined) { e.Graphics.DrawRectangle(dots, new Rectangle(2, 2, Width - 4, Height - 4)); } if (_showImage) { if (Height > 20) { e.Graphics.DrawImage(Image, new Rectangle(1, 1, Height - 2, Height - 2)); } else { e.Graphics.DrawImage(Image, new Rectangle(1, 1, Image.Width, Image.Height)); } left = Height + 2; } Brush b = new SolidBrush(_fontColor); e.Graphics.DrawString(Text, Font, b, new PointF(left, 1f)); b.Dispose(); if (specialDrawing) { if (border != null) { border.Dispose(); } if (innerBorder != null) { innerBorder.Dispose(); } if (fill != null) { fill.Dispose(); } if (dots != null) { dots.Dispose(); } } //base.OnPaint(e); }