private Size SizeItem(int offset, ILegendItem item, Graphics g) { if (item == null) { return(new Size(0, 0)); } int width = offset + 30 + (int)g.MeasureString(item.LegendText, Font).Width; int height = ItemHeight; if (item.LegendSymbolMode == SymbolMode.Symbol) { Size s = item.GetLegendSymbolSize(); if (s.Height > ItemHeight) { height = s.Height; } } if (item.IsExpanded) { if (item.LegendItems != null) { foreach (ILegendItem child in item.LegendItems) { Size cs = SizeItem(offset + _indentation, child, g); height += cs.Height; if (cs.Width > width) { width = cs.Width; } } } } return(new Size(width, height)); }
/// <summary> /// Draw the symbol for a particular item. /// </summary> /// <param name="g">Graphics object used for drawing.</param> /// <param name="topLeft">TopLeft position where the symbol should be drawn.</param> /// <param name="itemBox">LegendBox of the item, the symbol should be added to.</param> private void DrawSymbol(Graphics g, ref PointF topLeft, LegendBox itemBox) { ILegendItem item = itemBox.Item; // Align symbols so that their right side is about 20 pixels left // of the top-left X, but allow up to 128x128 sized symbols Size s = item.GetLegendSymbolSize(); int h = s.Height; if (h < 1) { h = 1; } if (h > 128) { h = 128; } int w = s.Width; if (w < 1) { w = 1; } if (w > 128) { w = 128; } int tH = ItemHeight; int x = (int)topLeft.X + tH - w; int y = (int)topLeft.Y; if (tH > h) { y += (tH - h) / 2; } Rectangle box = new Rectangle(x, y, w, h); itemBox.SymbolBox = box; item.LegendSymbolPainted(g, box); topLeft.X += tH + 6; }
private Size SizeItem(int offset, ILegendItem item, Graphics g) { if (item == null) return new Size(0, 0); int width = offset + 30 + (int)g.MeasureString(item.LegendText, Font).Width; int height = ItemHeight; if(item.LegendSymbolMode == SymbolModes.Symbol) { Size s = item.GetLegendSymbolSize(); if (s.Height > ItemHeight) height = s.Height; } if (item.IsExpanded) { if (item.LegendItems != null) { foreach (ILegendItem child in item.LegendItems) { Size cs = SizeItem(offset + _indentation, child, g); height += cs.Height; if (cs.Width > width) width = cs.Width; } } } return new Size(width, height); }