Basically, I have keywords like sin( and cos( in the text box that I want to keep as one character.
When I mention the entire line below, it refers to a group of characters (for example, " sin( ")
Using sin( as an example:
If the carriage was in this position (beyond s ):

If you press del , it will delete the whole line. If the right arrow key is pressed, the carriage will jump after ( .
If the carriage was in this position (after ( ):

If you click backspace , the entire line will be deleted. If the left arrow key was pressed, the carriage would move beyond s .
EDIT: Thanks to John Skeet who pointed this out.
Selecting any substring of a character group (for example, si from sin( ) should select the entire string.
Sorry if this is hard to understand, then what I mean is a little hard to put into words.
EDIT 2: Thanks to Darksheao for giving me an answer to the backspace and deleting the keys. I moved the delete segment to the PreviewKeyDown event since it does not work with the KeyPress event.
EDIT 3: Using the charCombinations way of doing things, here is how I made the implementation for the left and right keys:
#region Right case Keys.Right: { s = txt.Substring(caretLocation); foreach (string combo in charCombinations) { if (s.StartsWith(combo)) { textBox1.SelectionStart = caretLocation + combo.Length - 1; break; } } break; } #endregion #region Left case Keys.Left: { s = txt.Substring(0, caretLocation); foreach (string combo in charCombinations) { if (s.EndsWith(combo)) { textBox1.SelectionStart = caretLocation - combo.Length + 1; break; } } break; } #endregion
All that remains is the implementation of the mouse. Anyone? I also realized that the user can use the mouse to place the carriage in the middle of one of these lines, so when this happens, the mouse needs to be moved to the beginning of the line.