public static void SetTextBoxLocation(BaseElement element, TextBox textBox) { if (!(element is ILabelElement)) { return; } var label = ((ILabelElement)element).Label; element.Invalidate(); label.Invalidate(); if (label.Text.Length > 0) { textBox.Location = element.Location; textBox.Size = element.Size; } else { var sizeTmp = DiagramHelper.MeasureString("XXXXXXX", label.Font, label.Size.Width, label.Format); if (element is BaseLinkElement) { textBox.Size = sizeTmp; textBox.Location = new Point( element.Location.X + element.Size.Width / 2 - sizeTmp.Width / 2, element.Location.Y + element.Size.Height / 2 - sizeTmp.Height / 2); } else { sizeTmp.Width = element.Size.Width; textBox.Size = sizeTmp; textBox.Location = new Point(element.Location.X, element.Location.Y + element.Size.Height / 2 - sizeTmp.Height / 2); } } var rectangle = new Rectangle(textBox.Location, textBox.Size); rectangle.Inflate(3, 3); textBox.Location = rectangle.Location; textBox.Size = rectangle.Size; }
private Size MeasureTextSize() { var sizeTmp = Size.Empty; switch (_direction) { case LabelEditDirection.UpDown: sizeTmp = DiagramHelper.MeasureString(_labelTextBox.Text, _labelElement.Font, _labelTextBox.Size.Width, _labelElement.Format); break; case LabelEditDirection.Both: sizeTmp = DiagramHelper.MeasureString(_labelTextBox.Text, _labelElement.Font); break; } sizeTmp.Height += 30; return(sizeTmp); }
public static Size GetTextSize(BaseElement element) { var sizeTmp = Size.Empty; var direction = element is BaseLinkElement ? LabelEditDirection.Both : LabelEditDirection.UpDown; var labelElement = ((ILabelElement)element).Label; switch (direction) { case LabelEditDirection.UpDown: sizeTmp = DiagramHelper.MeasureString(labelElement.Text, labelElement.Font, labelElement.Size.Width, labelElement.Format); break; case LabelEditDirection.Both: sizeTmp = DiagramHelper.MeasureString(labelElement.Text, labelElement.Font); break; } sizeTmp.Height += 30; return(sizeTmp); }