No, you did not create Notepad application. Such application already existed (and it's extremely bad one, by the way). :-)
Also, there is no such thing as "focus" inside a control. This would mean "keyboard focus", and only one control in the whole system can get focus. Inside a control, this is selection. For text controls, this is selection and insertion point at the same time.
The answer depends on your UI library which you failed to specify, which is not nice of you, for who would like to provide redundant information?
For
System.Windows.Controls.TextBox
, you can use the property
CaretIndex
, please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.caretindex.aspx[
^].
For
System.Windows.Forms.TextBox
, this is two properties:
SelectionStart
and
SelectionLength
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectionstart.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectionlength.aspx[
^].
To find what character is on what line and visa versa, use the methods
GetFirstCharIndexFromLine
,
GetFirstCharIndexOfCurrentLine
and
GetLineFromCharIndex
.
—SA