Cursor Position
-
Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S
TextBox.SelectionStart
might be what you're looking for. Regards, mav -
Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S
I think you can get this information through evaluation of
SelectionStart
,SelectionLength
andSelectedText
properties. MSDN states that if no text is selected in the control, theSelectionStart
property indicates the insertion point for new text i.e. the current cursor position. If otherwise something is selected, the cursor position should be the sum ofSelectionStart
andSelectionLength
.int cursorPos;
if (textbox.SelectedText == string.Empty)
cursorPos = textbox.SelectionStart;
else
cursorPos = textbox.SelectionStart + textbox.SelectionLength;P.S: All information bases on research in MSDN topics, so the above code snippet isn't tested and comes without warranty :)
-
I think you can get this information through evaluation of
SelectionStart
,SelectionLength
andSelectedText
properties. MSDN states that if no text is selected in the control, theSelectionStart
property indicates the insertion point for new text i.e. the current cursor position. If otherwise something is selected, the cursor position should be the sum ofSelectionStart
andSelectionLength
.int cursorPos;
if (textbox.SelectedText == string.Empty)
cursorPos = textbox.SelectionStart;
else
cursorPos = textbox.SelectionStart + textbox.SelectionLength;P.S: All information bases on research in MSDN topics, so the above code snippet isn't tested and comes without warranty :)
-
Hi That did the job.. but i want to know is it possible to position (move the cursor where i want to move) the cursor inside the textbox thru code. Regards Deepak.S
It's all in the docs: MSDN topic of SelectionStart states: "You can programmatically move the caret within the text box by setting the SelectionStart to the position within the text box where you want the caret to move to and set the SelectionLength property to a value of zero (0). The text box must have focus in order for the caret to be moved."
-
Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S
System.Windows.Forms.Form.MousePosition so from inside the form code : MousePosition GanDad