public static int GetCaretPosition(TextBoxBase textBox) { if (textBox.InvokeRequired) { return (int)textBox.Invoke(new getCaretPosition(GetCaretPosition), textBox); } else { return textBox.SelectionStart; } }