MeasureString() public static method

public static MeasureString ( string text, Font font ) : Size
text string
font System.Drawing.Font
return System.Drawing.Size
Example #1
0
        private Size MeasureTextSize()
        {
            string text    = labelTextBox.Text;
            Size   sizeTmp = Size.Empty;

            if (direction == LabelEditDirection.UpDown)
            {
                sizeTmp = DiagramUtil.MeasureString(text, labelElement.Font, labelTextBox.Size.Width, labelElement.Format);
            }
            else if (direction == LabelEditDirection.Both)
            {
                sizeTmp = DiagramUtil.MeasureString(text, labelElement.Font);
            }

            sizeTmp.Height += 30;

            return(sizeTmp);
        }
Example #2
0
        public static void SetTextBoxLocation(BaseElement el, TextBox tb)
        {
            if (!(el is ILabelElement))
            {
                return;
            }

            LabelElement lab = ((ILabelElement)el).Label;

            el.Invalidate();
            lab.Invalidate();

            if (lab.Text.Length > 0)
            {
                tb.Location = lab.Location;
                tb.Size     = lab.Size;
            }
            else
            {
                string tmpText = "XXXXXXX";
                Size   sizeTmp = DiagramUtil.MeasureString(tmpText, lab.Font, lab.Size.Width, lab.Format);

                if (el is BaseLinkElement)
                {
                    tb.Size     = sizeTmp;
                    tb.Location = new Point(el.Location.X + (el.Size.Width / 2) - (sizeTmp.Width / 2),
                                            el.Location.Y + (el.Size.Height / 2) - (sizeTmp.Height / 2));
                }
                else
                {
                    sizeTmp.Width = el.Size.Width;
                    tb.Size       = sizeTmp;
                    tb.Location   = new Point(el.Location.X,
                                              el.Location.Y + (el.Size.Height / 2) - (sizeTmp.Height / 2));
                }
            }

            SetTextBoxBorder(tb);
        }