Is it possible to get the cursor position in any way in a textBox and also set a Cursorpositon.

I have tried out this syntax but am not sure if this is correct:
I dont know what this returns.

textBox1->Cursor->Position::get();
textBox1->Cursor->Position::set();

Recommended Answers

All 2 Replies

You can use the SelectionStart TextBox's property for that purpose.
Also closely related is the SelectionLength i.e. how many characters the selection spans (if any).
As an example, to place the cursor in front of the second character without selected text, you could use

textBox1->SelectionStart = 1;
textBox1->SelectionLength = 0;

Thanks, this seemed to work great.

You can use the SelectionStart TextBox's property for that purpose.
Also closely related is the SelectionLength i.e. how many characters the selection spans (if any).
As an example, to place the cursor in front of the second character without selected text, you could use

textBox1->SelectionStart = 1;
textBox1->SelectionLength = 0;
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.