This code tells what position the cursor is in a textbox.
Let us say that this position is 10.

Now is my question, is it possible to know what character it is if any on position 9 in the textBox.
Is it possible to put the character on position 9 to a string ?

int position;
position = textBox1->SelectionStart;

Recommended Answers

All 4 Replies

If that text box is like MFC then you have to get the string that's already in the box, make whatever changes you want, then put the entire string back.

I am not sure if you meen that it is possible to put the whole line that the cursor is to a String^ ?

If this is possible I think this can solve my problem. I think I am not sure how to put the current line to a string^ where the cursor is in a multilined textBox though.
Thanks.


If that text box is like MFC then you have to get the string that's already in the box, make whatever changes you want, then put the entire string back.

Put all the text in the box into a String, not necessarily what's at the current cursor position. But look in MSDN at the methods available for the text box and see if there is an easier way to do it, but I doubt it.

Thank you, I found out this solution with substring wich works fine.
Thanks.

int position = 0;

position = textbox->SelectionStart;
String^ Line;

if ( position >= 5 )
{
	Line = textbox->Text->Substring( (position - 5), 5);
}

Put all the text in the box into a String, not necessarily what's at the current cursor position. But look in MSDN at the methods available for the text box and see if there is an easier way to do it, but I doubt it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.