LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox

LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox

Post by bitwxtadp » Sun, 21 Aug 2005 02:06:30


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 in C#.

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.
 
 
 

LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox

Post by Doug Harri » Sun, 21 Aug 2005 02:17:36


In general, you should use SendInput for that purpose, but keep reading.


In Windows-speak, the "cursor" is the mouse cursor, and the "caret"
represents the insertion point. I think you mean the caret.


This is a C++ group, not C#, but those arguments aren't correct in either
language for those messages.


Use EM_CHARFROMPOS to convert coordinates to character position, and then
send EM_SETSEL, specifying this position for both the start and end
positions.

--
Doug Harrison
VC++ MVP

 
 
 

LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox

Post by Igor Tande » Sun, 21 Aug 2005 02:19:30


EM_CHARFROMPOS to determine character position from mouse coordinates.
Then just use Select method.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
 
 
 

LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox

Post by bitwxtadp » Thu, 25 Aug 2005 04:47:12

Thanks for the feed back.
Sorry for the confusion on the terms - Yes I meant the cursor in the
TextBox.
I thought that someone with a C++ backgound would better know about
sending messages than somsone in the C# group.
Why do you say that the arguments are not correct for C#?

Ok, so let me explain the situation a bit more precisely.
I have a control named "Outer" that when I click on it with the
mouse I want to pass the mouse click into a new control named
"Inner". The "Inner" control is created and added to the
"Outer" control in the OnMouseClick event and the exact type of the
"Inner" control is unknown at design time.

To pass the mouse click onto the "Inner" control I send
WM_RBUTTONDOWN and a WM_RBUTTONUP messages to it.
This seems to work well. However, when the "Inner" control is a
TextBox, half of the time the text gets select from the start of the
TextBox to where I clicked.

I suspect that there is a message I'm not sending, or a way to
unselect the text.
Any ideas?
Thanks,
Brian.