Example #1
2
        protected void UpdateCursorLocation(TextBox tb)
        {
            cursorLineNo = tb.GetLineFromCharIndex(tb.SelectionStart) + 1;
             cursorColumnNo = tb.SelectionStart - tb.GetFirstCharIndexOfCurrentLine() + 1;

             // Update cursor position on status bar:

             mainStatusStripCursorPosLabel.Text = "(" + cursorLineNo.ToString() + ", " +
             cursorColumnNo.ToString() + ")";
        }
 /// <summary>
 /// Gets the current line from a TextBox control.
 /// </summary>
 /// <param name="tb">the TextBox control.</param>
 /// <returns>the current line.</returns>
 public static String getCurrentLine(TextBox tb)
 {
     if (tb.Lines.Length == 0)
     {
         return tb.Text;
     }
     else
     {
         int startIndex = tb.GetFirstCharIndexOfCurrentLine();
         int currentLineNumber = tb.GetLineFromCharIndex(startIndex);
         return tb.Lines[currentLineNumber];
     } 
 }
Example #3
0
        public static Point GetCaretPosition(this TextBox textBox)
        {
            Point point = new Point(0, 0);

            if (textBox.Focused)
            {
                point.X = textBox.SelectionStart - textBox.GetFirstCharIndexOfCurrentLine() + 1;
                point.Y = textBox.GetLineFromCharIndex(textBox.SelectionStart) + 1;
            }
            return(point);
        }
 /// <summary>
 /// Gets the current line number.
 /// </summary>
 /// <param name="tb">a TextBox.</param>
 /// <returns>the current line number.</returns>
 public static int getCurrentLineNo(TextBox tb)
 {
     if (tb.Lines.Length == 0)
     {
         return 0;
     }
     else
     {
         int startIndex = tb.GetFirstCharIndexOfCurrentLine();
         return tb.GetLineFromCharIndex(startIndex);
     } 
 }
 /// <summary>
 /// Gets a key/value pair containing currentLineNumber/currentLine.
 /// </summary>
 /// <param name="tb">the TextBox.</param>
 /// <returns>a key/value pair containing currentLineNumber/currentLine.</returns>
 public static KeyValuePair<int, String> getCurrentLineAndLineNo(TextBox tb)
 {
     if (tb.Lines.Length == 0)
     {
         return new KeyValuePair<int, String>(0,tb.Text);
     }
     else
     {
         int startIndex = tb.GetFirstCharIndexOfCurrentLine();
         int currentLineNumber = tb.GetLineFromCharIndex(startIndex);
         return new KeyValuePair<int,String>(currentLineNumber, tb.Lines[currentLineNumber]);
     } 
 }
Example #6
0
 /// <include file='doc\ToolStripTextBox.uex' path='docs/doc[@for="ToolStripTextBox.GetFirstCharIndexOfCurrentLine"]/*' />
 public int GetFirstCharIndexOfCurrentLine()
 {
     return(TextBox.GetFirstCharIndexOfCurrentLine());
 }