Пример #1
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);
		}
Пример #2
0
		int GetOffset(TextBox textBox, AstLocation location)
		{
			return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1;
		}
Пример #3
0
 /// <include file='doc\ToolStripTextBox.uex' path='docs/doc[@for="ToolStripTextBox.GetFirstCharIndexFromLine"]/*' />
 public int GetFirstCharIndexFromLine(int lineNumber)
 {
     return(TextBox.GetFirstCharIndexFromLine(lineNumber));
 }
Пример #4
0
		int GetOffset(TextBox textBox, TextLocation location)
		{
			// TextBox uses 0-based coordinates, TextLocation is 1-based
			return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1;
		}
Пример #5
-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();
        }