Ejemplo n.º 1
0
        public static Size MeasureString(string text, Font font, Size constraints, bool multiline, bool textboxControl)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(new Size());
            }
            Graphics gr     = CompactFactory.Instance.RootForm.CreateGraphics();
            var      bounds = new Rect
            {
                Left   = 0,
                Top    = 0,
                Bottom = (int)constraints.Height,
                Right  = (int)constraints.Width,
            };
            var hFont          = font.ToHfont();
            var hdc            = gr.GetHdc();
            var originalObject = SelectObject(hdc, hFont);
            int flags          = DT_CALCRECT;

            if (multiline)
            {
                flags |= DT_WORDBREAK;
            }
            if (textboxControl)
            {
                flags |= DT_EDITCONTROL;
            }
            DrawText(hdc, text, text.Length, ref bounds, flags);
            SelectObject(hdc, originalObject);
            gr.ReleaseHdc(hdc);
            return(new Size(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top + (textboxControl ? 6 : 0)));
        }
Ejemplo n.º 2
0
        public override void SetLocation(Point location, Size size)
        {
            if (Math.Abs(MeasuredHeight - size.Height) > .001)
            {
                this.MeasureView(size);
            }

            SetWidth((int)size.Width);

            var left   = location.X;
            var right  = location.X + size.Width;
            var top    = location.Y;
            var bottom = location.Y + MeasuredHeight;

            Layout((int)left, (int)top, (int)right, (int)bottom);
        }
Ejemplo n.º 3
0
 public override Size Measure(Size constraints)
 {
     return(this.MeasureView(constraints));
 }