コード例 #1
0
        public virtual RectangleF GetRectangleFromCharacterIndex(int index, bool trailEdge)
        {
            string text = this.GetText();

            if (index < 0 || index > text.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            Size size       = Size.Empty;
            Font scaledFont = this.GetScaledFont(this.DpiScaleFactor.Height);

            if (index == 0 && !trailEdge)
            {
                size.Height = (int)this.DesiredSize.Height;
            }
            else if (index == this.text.Length && trailEdge)
            {
                size = this.DesiredSize.ToSize();
            }
            else
            {
                if (trailEdge)
                {
                    ++index;
                }
                size = TextBoxControlMeasurer.MeasureText(text.Substring(0, index), scaledFont);
            }
            RectangleF rectangleF = new RectangleF((PointF)this.ControlBoundingRectangle.Location, new SizeF(0.0f, (float)size.Height));

            rectangleF.X += (float)size.Width;
            return(rectangleF);
        }
コード例 #2
0
        public static int BinarySearchCaretIndex(string text, Font font, double availableWidth)
        {
            if (text.Length == 0)
            {
                return(0);
            }
            int index = -1;
            int num1  = 0;
            int num2  = text.Length - 1;
            int num3  = 0;

            while (num1 <= num2)
            {
                index = num1 + (num2 - num1 >> 1);
                num3  = TextBoxControlMeasurer.MeasureText(text.Substring(0, index + 1), font).Width;
                if ((double)num3 <= availableWidth)
                {
                    num1 = index + 1;
                }
                else
                {
                    num2 = index - 1;
                }
            }
            if (index + 1 < text.Length)
            {
                ++index;
            }
            else
            {
                num3 = TextBoxControlMeasurer.MeasureText(text.Substring(0, index), font).Width;
            }
            if ((double)num3 != availableWidth)
            {
                int num4 = TextBoxControlMeasurer.MeasureText(text[index].ToString(), font).Width / 2;
                if ((double)num3 < availableWidth)
                {
                    if ((double)(num3 + num4) <= availableWidth)
                    {
                        ++index;
                    }
                }
                else if ((double)(num3 - num4) > availableWidth)
                {
                    --index;
                }
            }
            return(Math.Max(index, 0));
        }
コード例 #3
0
        public static int BinarySearchWrapIndex(string text, Font font, float availableWidth)
        {
            if (text.Length == 0)
            {
                return(0);
            }
            int    length = -1;
            int    num1   = 0;
            int    num2   = text.Length - 1;
            string empty  = string.Empty;
            float  num3   = float.MaxValue;
            int    num4   = 0;

            while (num1 <= num2)
            {
                length = (num2 + num1) / 2;
                int width = TextBoxControlMeasurer.MeasureText(text.Substring(0, length), font).Width;
                if ((double)num3 < (double)availableWidth && (double)width > (double)availableWidth)
                {
                    length = num4;
                    break;
                }
                if ((double)width != (double)availableWidth)
                {
                    if ((double)width < (double)availableWidth)
                    {
                        num1 = length + 1;
                    }
                    else
                    {
                        num2 = length - 1;
                    }
                    num4 = length;
                    num3 = (float)width;
                }
                else
                {
                    break;
                }
            }
            while (length < text.Length && (double)TextBoxControlMeasurer.MeasureText(text.Substring(0, length + 1), font).Width <= (double)availableWidth)
            {
                ++length;
            }
            return(length);
        }
コード例 #4
0
        protected override SizeF MeasureOverride(SizeF availableSize)
        {
            if (!this.performMeasure)
            {
                return(this.DesiredSize);
            }
            this.performMeasure = false;
            string text = this.GetText();
            bool   flag = string.IsNullOrEmpty(text);

            if (flag)
            {
                text = "X";
            }
            SizeF sizeF = (SizeF)TextBoxControlMeasurer.MeasureText(text, this.GetScaledFont(this.DpiScaleFactor.Height));

            if (flag)
            {
                sizeF.Width = 0.0f;
            }
            return(sizeF);
        }
コード例 #5
0
        protected override void PaintElement(IGraphics graphics, float angle, SizeF scale)
        {
            if (this.drawFill)
            {
                base.PaintElement(graphics, angle, scale);
            }
            if (this.text == null || this.text.Trim() == string.Empty)
            {
                return;
            }
            Graphics          underlayGraphics  = graphics.UnderlayGraphics as Graphics;
            TextRenderingHint textRenderingHint = underlayGraphics.TextRenderingHint;

            underlayGraphics.TextRenderingHint = TextRenderingHint.SystemDefault;
            Point location = this.ControlBoundingRectangle.Location;

            --location.Y;
            List <string> textParts = this.GetTextParts();
            int           count     = textParts.Count;
            Color         foreColor = this.ForeColor;
            Color         backColor = this.Enabled ? Color.Transparent : this.BackColor;

            using (RadHdcWrapper radHdcWrapper = new RadHdcWrapper(underlayGraphics, false))
            {
                for (int index = 0; index < count; ++index)
                {
                    string text = textParts[index];
                    TextRenderer.DrawText((IDeviceContext)radHdcWrapper, text, this.GetScaledFont(this.DpiScaleFactor.Height), location, foreColor, backColor, TextFormatFlags.NoClipping | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding);
                    if (index < count - 1)
                    {
                        Size size = TextBoxControlMeasurer.MeasureText(text, this.GetScaledFont(this.DpiScaleFactor.Height));
                        location.X += size.Width;
                    }
                }
            }
            underlayGraphics.TextRenderingHint = textRenderingHint;
        }