473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WM_RBUTTONDOWN WM_RBUTTONUP selects text I don't want selected in a textbox

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

Nov 17 '05 #1
3 3997
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

Nov 17 '05 #2
Thanks for the feed back.
Sorry for the confusion on the terms - Yes I meant the blinking cursor
in the text box not the mouse cursor.
I don't have access to the text box since the type of the control is
not known at design time.

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 selected 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.

Nov 17 '05 #3
Thanks for the feed back.
Sorry for the confusion on the terms - Yes I meant the blinking cursor
in the text box not the mouse cursor.
I don't have access to the text box since the type of the control is
not known at design time.

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 selected 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.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdawg | last post by:
what i want to do is create several radio buttons and a textbox for searching purposes. the search will perform a search depending on which button the user selects. here is what i have now: ...
7
by: Nick Calladine | last post by:
Hi On my form i have multiple select which all have an id value total1, total2, total3 etc so i am trying to detect how many there are and then use this to caculate a total. Is there a...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
1
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number...
8
by: cj | last post by:
I asked this question a couple of days ago but am just now looking at it again. I used to use the textbox gotfoucs event to have all the text in the textbox selected when it gotfocus. That...
0
by: andytsummers | last post by:
Hi I have tried to implement drag and drop by using the following code but I have several problems. 1. When you put your mouse over selected text the cursor is still the i-beam and therefore...
14
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
4
by: darith | last post by:
Hi all, I want to know code in vb.net to get number of selected text in MS Word. how can we write? Please help me. I need it urgent. in textbox we just write textbox.selectedtext so we can get...
1
by: sbandalli | last post by:
Hello, I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category) ,and Datagridview is not bounded to any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.