I want to programmaticall y 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(tex tBox1.Handle, WM_LBUTTONDOWN, Y,X);
SendMessage(tex tBox1.Handle, WM_LBUTTONUP, Y,X);
Is there another message I can send?
Thanks,
Brian 3 4010
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
GetCharIndexFro mPosition 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.co m
<bi********@yah oo.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. . I want to programmaticall y 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(tex tBox1.Handle, WM_LBUTTONDOWN, Y,X); SendMessage(tex tBox1.Handle, WM_LBUTTONUP, Y,X);
Is there another message I can send? Thanks, Brian
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
- for each radio button, i use the onClick event handler, which calls
a function called showMe()
- showMe() {
|
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 javascript reference to basically go to a form and produce a loop
which will show me how many select drop down boxes there on a form.
Or would i have t use something like
|
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 it return the
associated records to a listbox. Once the listbox has the records, I
want to select a record, which will open a form associated with the
selected record in the listbox.
|
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 has an upper limit. I want to do
validation on what the user enters as they type it in.
I set up an event handler for KeyPress that restricts them from being
able to enter non-numeric characters (only allowing numbers, decimal
point, control...
|
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 doesn't seem to work in .net
when the textbox receives focus via a mouse click.
Jeffrey and Shane both advised how to get a mouse click to select all
the text (thank you both) but using the mousedown or mouseup events
doesn't work the way I want it...
| |
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 does not show that the text can be dragged
2. When pressing the mouse button to start a drag the selected text
changes - I know this is cause the code does not initiate the
dodragdrop until the mouse leaves the control but if I change this
then you...
|
by: > Adrian |
last post by:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
|
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 number of selected text but in MS word i don't understand how can we write to get number selcted text in MS word?
one problem in textbox if we want to start selction we just write textbox.selectionstart, but if we want ms word start selection text...
|
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 datasource. When the user selects an item in the combobox,and enters the item(text) in the 2 text box , I want all the 3(combobox selected item, and the entered text in the 2 textbox) of them to store it a a table name called...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |