ACAT.Extensions.Default.FunctionalAgents.LectureManager.LectureManagerMainForm.setCaretPosAndSelect C# (CSharp) Method

setCaretPosAndSelect() private method

Highlights text starting at the specified position and length
private setCaretPosAndSelect ( int pos, int length ) : void
pos int starting offset
length int number of chars to highlight
return void
        private void setCaretPosAndSelect(int pos, int length = 0)
        {
            textBox1.Focus();
            textBox1.Select(pos, length);

            Rectangle textBoxBounds = this.textBox1.Bounds;
            textBoxBounds = textBox1.Parent.RectangleToScreen(textBoxBounds);

            Point caretLocation = textBox1.GetPositionFromCharIndex(textBox1.SelectionStart);
            caretLocation = textBox1.Parent.PointToScreen(caretLocation);

            Log.Debug("textBounds.Top: " + textBoxBounds.Top +
                        ", caretLocation.Y : " + caretLocation.Y +
                        ", scrolllines*textheight: " + (ScrollThresholdLines * _textHeight));

            if ((textBoxBounds.Bottom - caretLocation.Y) <= ScrollThresholdLines * _textHeight)
            {
                Log.Debug("Scrolling down...");
                SendMessage(textBox1.Handle, EM_LINESCROLL, 0, ScrollNumberOfLines);
            }
            else
            {
                if (caretLocation.Y < 0)
                {
                    Log.Debug("caretLocation is negative. Calling scroll to caret");
                    textBox1.ScrollToCaret();
                }

                caretLocation = textBox1.GetPositionFromCharIndex(textBox1.SelectionStart);
                caretLocation = textBox1.Parent.PointToScreen(caretLocation);

                if (caretLocation.Y - textBoxBounds.Top <= ScrollThresholdLines * _textHeight)
                {
                    Log.Debug("Scrolling up...");
                    SendMessage(textBox1.Handle, EM_LINESCROLL, 0, -ScrollNumberOfLines);
                }
            }

            Log.Debug("setCaretPos.  SelectionStart: " + textBox1.SelectionStart);
        }