예제 #1
0
        private void SelectCurrentLine()
        {
            StartOfLineCommand startOfLineCommand = new StartOfLineCommand(richEditControl1);
            EndOfLineCommand   endOfLineCommand   = new EndOfLineCommand(richEditControl1);

            startOfLineCommand.Execute();

            int start = richEditControl1.Document.CaretPosition.ToInt();

            endOfLineCommand.Execute();

            int length = richEditControl1.Document.CaretPosition.ToInt() - start;

            DocumentRange AITextRange            = richEditControl1.Document.CreateRange(start, length);
            DocumentRange AITextRangeWithNewLine = richEditControl1.Document.CreateRange(start, length + 1);

            string text = richEditControl1.Document.GetText(AITextRangeWithNewLine);

            if (text.EndsWith(Environment.NewLine))
            {
                richEditControl1.Document.Selection = AITextRangeWithNewLine;
            }
            else
            {
                richEditControl1.Document.Selection = AITextRange;
            }
        }
        DocumentRange GetNewLineRange(DocumentPosition caret)
        {
            isSelectionLocked = true;
            DocumentPosition currentPosition = richEditControl1.Document.CaretPosition;

            StartOfLineCommand startOfLineCommand = new StartOfLineCommand(richEditControl1);
            EndOfLineCommand   endOfLineCommand   = new EndOfLineCommand(richEditControl1);

            startOfLineCommand.Execute();

            int start = richEditControl1.Document.CaretPosition.ToInt();

            endOfLineCommand.Execute();

            int length = richEditControl1.Document.CaretPosition.ToInt() - start;

            DocumentRange range  = richEditControl1.Document.CreateRange(start, length);
            DocumentRange range2 = richEditControl1.Document.CreateRange(start, length + 1);

            string text = richEditControl1.Document.GetText(range2);

            richEditControl1.Document.CaretPosition = currentPosition;
            isSelectionLocked = false;
            if (text.EndsWith(Environment.NewLine))
            {
                return(range2);
            }
            else
            {
                return(range);
            }
        }