コード例 #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
        protected virtual bool SplitBlock(
            LineInfo currentLine,
            SizeF availableSize,
            ref ITextBlock textBlock,
            ref int offset)
        {
            string text1 = textBlock.Text;
            int    num   = TextBoxControlMeasurer.BinarySearchWrapIndex(text1, this.Font, availableSize.Width);

            switch (num)
            {
            case -1:
            case 0:
                return(false);

            default:
                if (num != text1.Length)
                {
                    string str   = text1.Substring(0, num);
                    string text2 = text1.Substring(num);
                    textBlock.Text   = str;
                    textBlock.Offset = offset;
                    offset          += textBlock.Length;
                    int index1 = textBlock.Index;
                    this.MeasureTextBlock(textBlock, availableSize);
                    currentLine.EndBlock = textBlock;
                    this.AddBlockDesiredSize(textBlock.DesiredSize, currentLine);
                    int index2 = index1 + 1;
                    textBlock = this.CreateBlock(text2, TextBoxWrapPanel.TextBlockElementType);
                    this.Children.Insert(index2, textBlock as RadElement);
                    return(true);
                }
                goto case -1;
            }
        }
コード例 #3
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));
        }
コード例 #4
0
        public virtual int GetCharacterIndexFromX(float x)
        {
            int num = 0;
            int x1  = this.ControlBoundingRectangle.X;

            if ((double)x >= (double)this.ControlBoundingRectangle.Right)
            {
                num = this.Length;
            }
            else if ((double)x > (double)x1)
            {
                num = TextBoxControlMeasurer.BinarySearchCaretIndex(this.GetText(), this.GetScaledFont(this.DpiScaleFactor.Height), (double)(x - (float)x1));
            }
            return(num);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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;
        }