Esempio n. 1
0
        public virtual bool ScrollToCaret()
        {
            TextBoxControlCaret caret      = this.TextBoxElement.Caret;
            RadScrollBarElement hscrollBar = this.textBoxElement.HScrollBar;
            RadScrollBarElement vscrollBar = this.textBoxElement.VScrollBar;

            if (caret == null || this.CaretPosition == (TextPosition)null)
            {
                vscrollBar.Value = vscrollBar.Minimum;
                hscrollBar.Value = hscrollBar.Minimum;
                return(false);
            }
            RectangleF boundingRectangle = (RectangleF)caret.ControlBoundingRectangle;
            RectangleF viewportBounds    = (RectangleF)this.TextBoxElement.ViewElement.ViewportBounds;
            float      num1         = 0.0f;
            float      num2         = 0.0f;
            LineInfo   line         = this.CaretPosition.Line;
            ITextBlock textBlock    = this.CaretPosition.TextBlock;
            int        charPosition = this.CaretPosition.CharPosition;

            if (textBlock == line.StartBlock && charPosition == 0)
            {
                num1 = (float)(hscrollBar.Minimum - hscrollBar.Value);
            }
            else if ((double)boundingRectangle.X > (double)viewportBounds.Right || (double)boundingRectangle.X < (double)viewportBounds.Left)
            {
                num1 = boundingRectangle.X - viewportBounds.X - viewportBounds.Width / 2f;
            }
            this.SetScrollBarValue(hscrollBar, hscrollBar.Value + (int)num1);
            if (this.textBoxElement.Multiline)
            {
                if (line == this.textBoxElement.ViewElement.Lines.FirstLine)
                {
                    num2 = (float)(vscrollBar.Minimum - vscrollBar.Value);
                }
                else if (line == this.textBoxElement.ViewElement.Lines.LastLine)
                {
                    int num3 = this.textBoxElement.ViewElement.VScroller.MaxValue - 1;
                    if (num3 != 0)
                    {
                        num2 = (float)(num3 - vscrollBar.Value + 1);
                    }
                }
                else if ((double)boundingRectangle.Top < (double)viewportBounds.Top)
                {
                    num2 = boundingRectangle.Top - viewportBounds.Top;
                }
                else if ((double)boundingRectangle.Bottom > (double)viewportBounds.Bottom)
                {
                    num2 = boundingRectangle.Bottom - viewportBounds.Bottom;
                }
                this.SetScrollBarValue(vscrollBar, vscrollBar.Value + (int)num2);
            }
            return(true);
        }
Esempio n. 2
0
        public virtual void SetCaretPosition()
        {
            if (this.selectionStart == (TextPosition)null)
            {
                return;
            }
            TextBoxControlCaret caret         = this.textBoxElement.Caret;
            TextPosition        caretPosition = this.CaretPosition;
            TextBoxViewElement  viewElement   = this.textBoxElement.ViewElement;
            PointF location     = viewElement.GetLocation(caretPosition);
            SizeF  scrollOffset = viewElement.ScrollOffset;

            location.X  += scrollOffset.Width;
            location.Y  += scrollOffset.Height;
            caret.Height = (int)caretPosition.Line.Size.Height;
            Point point = this.textBoxElement.PointFromControl(Point.Truncate(location));

            caret.Position = point;
        }