Round() public static method

Converts a SizeF to a Size by performing a round operation on all the coordinates.
public static Round ( SizeF value ) : Size
value SizeF
return Size
Exemplo n.º 1
0
        public void Print(PrintPageEventArgs e, Brush brush, Point moveAll)
        {
            if (Font == null)
            {
                throw new ArgumentNullException("Line.Font");
            }
            if (Font.Value == null)
            {
                throw new ArgumentNullException("Line.Font.Value");
            }

            var lines = Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            Size size;

            for (int i = 0, y = (int)Y; i < lines.Length; i++, y += size.Height)
            {
                e.Graphics.DrawString(lines[i], Font.Value, brush, X + moveAll.X, y + moveAll.Y);
                size = SSize.Round(e.Graphics.MeasureString(lines[i], Font.Value));
            }
        }
Exemplo n.º 2
0
            private void CheckAndUpdateWidth()
            {
                if (sf == null)
                {
                    sf = new StringFormat(StringFormat.GenericTypographic);
                }

                int fieldWidth = 0;

                if (TextWrap)
                {
                    fieldWidth = InitialSize.Width;
                }
                else
                {
                    fieldWidth = 9999999;                     // todo: avoid unsafe magic number
                }

                if (TextWrap)
                {
                    sf.FormatFlags &= ~StringFormatFlags.NoWrap;
                }
                else
                {
                    sf.FormatFlags |= StringFormatFlags.NoWrap;
                }

                Size size = Size.Round(graphics.MeasureString(Text, Font, fieldWidth, sf));

                if (TextWrap)
                {
                    this.SuspendLayout();

                    if (Height < size.Height)
                    {
                        int offset = size.Height - Height + 1;

                        Height += offset;

                        if (Height < Font.Height)
                        {
                            offset = Font.Height - Height;
                        }

                        Height += offset;

                        switch (VAlign)
                        {
                        case ReoGridVerAlign.Top:
                            break;

                        default:
                        case ReoGridVerAlign.Middle:
                            Top -= offset / 2;
                            break;

                        case ReoGridVerAlign.Bottom:
                            Top -= offset;
                            break;
                        }
                    }

                    this.ResumeLayout();
                }
                else
                {
                    this.SuspendLayout();

                    if (Width < size.Width + 5)
                    {
                        int widthOffset = size.Width + 5 - Width;

                        switch (TextAlign)
                        {
                        default:
                        case HorizontalAlignment.Left:
                            break;

                        case HorizontalAlignment.Right:
                            Left -= widthOffset;
                            break;
                        }

                        Width += widthOffset;
                    }

                    if (Height < size.Height + 1)
                    {
                        int offset = size.Height - 1 - Height;
                        Top   -= offset / 2 + 0;
                        Height = size.Height + 1;
                    }

                    this.ResumeLayout();
                }
            }