Exemple #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];
     } 
 }
Exemple #3
1
		TextLocation GetTextLocation(TextBox textBox, int offset)
		{
			int line = textBox.GetLineFromCharIndex(offset);
			int col = offset - textBox.GetFirstCharIndexFromLine(line);
			return new TextLocation(line + 1, col + 1);
		}
Exemple #4
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]);
     } 
 }
Exemple #7
0
 /// <include file='doc\ToolStripTextBox.uex' path='docs/doc[@for="ToolStripTextBox.GetLineFromCharIndex"]/*' />
 public int GetLineFromCharIndex(int index)
 {
     return(TextBox.GetLineFromCharIndex(index));
 }
Exemple #8
-1
        /// <summary>
        /// Generates a SQL File and saves it in the SQL folder.
        /// </summary>
        /// <param name="fileStart">The beginning of the fileName</param>
        /// <param name="fileName">FileName after fileStart (usually entry & name)</param>
        /// <param name="tb">The textbox to create from (text)</param>
        private void GenerateSQLFile(string fileStart, string fileName, TextBox tb)
        {
            // Save location / path
            string path = @".\SQL\" + fileStart + fileName + ".SQL";

            // Checks if the path file exists
            if (File.Exists(path))
            {
                // Creates a messagebox with a warning
                DialogResult dr = MessageBox.Show("File already exists.\n Replace it?", "Warning ...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                // If the feedback is no, stop the program from running
                if (dr == DialogResult.No)
                {
                    return;
                }
            }
            else
            {
                DialogResult dr = MessageBox.Show("SQL folder does not exist. \nAutomatically create one for you?", "The folder 'SQL' could not been found.", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                if (dr == DialogResult.Yes)
                {
                    Directory.CreateDirectory(@".\SQL\");
                }
                else
                {
                    return;
                }
            }

            // Checks if textbox is empty OR fileName is empty
            if (tb.TextLength == 0 || fileName == string.Empty)
            {
                return;
            }

            // StreamWriter is used to write the SQL.
            StreamWriter sw = new StreamWriter(path);

            // Puts every line of the selected textbox in an array.
            int lineCount = tb.GetLineFromCharIndex(tb.Text.Length) + 1;

            for (var i = 0; i < lineCount; i++)
            {
                int startIndex = tb.GetFirstCharIndexFromLine(i);

                int endIndex = (i < lineCount - 1) ?
                    tb.GetFirstCharIndexFromLine(i + 1) : tb.Text.Length;

                sw.WriteLine(tb.Text.Substring(startIndex, endIndex - startIndex));
            }

            // Closes the StreamWriter.
            sw.Close();
        }
Exemple #9
-1
 void Grow(TextBox child)
 {
     //Amount of padding to add
     const int padding = 3;
     //get number of lines (first line is 0)
     int numLines = child.GetLineFromCharIndex(child.TextLength) + 1;
     //get border thickness
     int border = child.Height - child.ClientSize.Height;
     //set height (height of one line * number of lines + spacing)
     child.Height = child.Font.Height * numLines + padding + border;
 }
        private void PasteString(TextBox oTB, string sText)
        {
            StringBuilder oBuffer = new StringBuilder(sText);

            if (sText == Environment.NewLine)
            {
                int iSelStart = oTB.SelectionStart;
                int iLigne = oTB.GetLineFromCharIndex(iSelStart);

                if (oTB.Lines.Length > iLigne)
                {
                    string sLigne = oTB.Lines[iLigne];
                    foreach (char c in sLigne)
                    {
                        if (c == ' ' || c == '\t')
                        {
                            oBuffer.Append(c);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            oTB.Paste(oBuffer.ToString());
        }