private SizeD CalculateSize() { ListField listField = ListField; int count = this.GetItemCount(listField); double height = HeaderBounds.Height + listField.GetItemHeight(this) * count; double width = 0; BarkerEntityShape entityShape = ParentShape as BarkerEntityShape; string entityName = entityShape.AccessibleName; StyleSet styleSet = StyleSet; Font defaultFont = styleSet.GetFont(listField.NormalFontId); Font alternateFont = styleSet.GetFont(listField.AlternateFontId); Font entityNameFont = entityShape.StyleSet.GetFont(new StyleSetResourceId(string.Empty, "ShapeTextBold10")); using (Graphics g = Graphics.FromHwnd(GetDesktopWindow())) { double entityNameWidth = (double)g.MeasureString(entityName, entityNameFont, int.MaxValue, DefaultStringFormat).Width + BarkerEntityExtraWidth; // Changes the width if the current width is less than the width of the table name. if (width < entityNameWidth) { width = entityNameWidth; } // Iterates through the column list to check the widths of the column names. for (int i = 0; i < count; ++i) { ItemDrawInfo itemDrawInfo = new ItemDrawInfo(); GetItemDrawInfo(listField, i, itemDrawInfo); bool isMandatory = (this.Items[i] as Barker.Attribute).IsMandatory; string text = itemDrawInfo.Text; // Gets the size of the column name in the context of the compartment double stringWidth = (double)g.MeasureString(text, isMandatory ? alternateFont : defaultFont, int.MaxValue, DefaultStringFormat).Width + AttributeExtraWidth; // Changes the width if the current width is less than the width of the column name. if (width < stringWidth) { width = stringWidth; } } } return(new SizeD(width, height)); }
/// <summary> /// Draw the various constraint types /// </summary> protected override void OnPaintShape(DiagramPaintEventArgs e, ref PaintHelper paintHelper) { base.OnPaintShape(e, ref paintHelper); RectangleD bounds = AbsoluteBounds; Graphics g = e.Graphics; StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; Font font = StyleSet.GetFont(FrequencyConstraintTextResource); g.DrawString(GetFrequencyString(), font, paintHelper.Brush, RectangleD.ToRectangleF(bounds), stringFormat); }