Brian,
I think you are confusing the terms somewhat. I think what you really
want is to move the caret position (the blinking sliver or box), and not the
cursor.
In order to set the caret position, just call the Select method on the
TextBox, passing the index you want to start selecting at, and then the
length of the text you want to select (set to zero in this case). You can
also achieve the same thing by setting the SelectionStart and
SelectionLength properties on the textbox.
If you are using .NET 2.0, you can find the index to send by calling the
GetCharIndexFromPosition method on the textbox. If you don't have .NET 2.0,
you can call SendMessage to the textbox, passing the EM_CHARFROMPOS message
(0xd7) to get the index of the character.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
<bi********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I want to programmatically set the position of a cursor in a textbox
that has focus based on a X and Y value.
However, when I send a WM_RBUTTONDOWN and a WM_RBUTTONUP message to the
textbox it selects the text from where the cursor is to where I want
the cursor to be. All I want is to move the position of the cursor
based on a X and Y values, not select the text.
The code to recreate the issue.
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
textBox1.Focus();
int X = 23;
int Y = 6;
SendMessage(textBox1.Handle, WM_LBUTTONDOWN, Y,X);
SendMessage(textBox1.Handle, WM_LBUTTONUP, Y,X);
Is there another message I can send?
Thanks,
Brian