473,513 Members | 3,317 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox: get text at/around mouse position

In a TextBox, I'm using a MouseMove event to track the cursor position.

I want to get able to tell what text the current cursor position is at so I
can set the SelectionStart to that position.

private void textBox1_MouseMove(object sender, MouseEventArgs e)
{
Point p = textBox1.PointToClient(new Point(e.X, e.Y));
/* now what to do I do with Point to figure out the character
position in the text box??? */

SelectionStart = ????
}

The only solution I can figure out so far is to call the Windows API
user.dll and send a click event. This effectively sets the SelectionStart
position. Is there a way to send a click all within .NET and not use the
API?

Better yet would just to be able to determine directly the current character
position in the (multi-line) TextBox.
Nov 16 '05 #1
1 6366
"Jed Ozone" <jed oz***@yahoo.com> schrieb im Newsbeitrag
news:ea****************@TK2MSFTNGP14.phx.gbl...
In a TextBox, I'm using a MouseMove event to track the cursor position.

I want to get able to tell what text the current cursor position is at so I can set the SelectionStart to that position.


What about the SelectionStart property?

private void textBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
MessageBox.Show(this.textBox1.SelectionStart.ToStr ing());
}

Is that what you need?
Greetings,
Tim.
Nov 16 '05 #2

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

Similar topics

10
3534
by: Alex | last post by:
could someone please point me to a site with an explanation or give me a *very* simple example of a div that would open right below a textbox on a page. I've seen lots of examples out there. Unfortunately I don't have time right now to dig through that code to extract the basic functionality. The one implementation that really hits the spot...
2
15600
by: bullshark | last post by:
VSN03:C# Create a C# Windows Form project. Add two TextBox controls. From the Properties of each, add an Enter Event handler. In the generated Enter Event Handlers (textBox1_Enter & textBox2_Enter ), add the code TextBox1.SelectAll(); and TextBox2.SelectAll(); Run the App. When you run the app with a breakpoint at textBox1_Enter(), and
0
502
by: Jed Ozone | last post by:
In a TextBox, I'm using a MouseMove event to track the cursor position. I want to get able to tell what text the current cursor position is at so I can set the SelectionStart to that position. private void textBox1_MouseMove(object sender, MouseEventArgs e) { Point p = textBox1.PointToClient(new Point(e.X, e.Y)); /* now what to do I do...
1
3821
by: objectref | last post by:
Hi to all, we have the MousePosition property that we can get the Point of the position of the mouse cursor on the screen, but is it there a way to get the respective Point of a cursor in a TextBox ?? (relative to screen) I mean, i have a textbox that i write some text and i want to know the exact point location of the cursor at any...
5
2971
by: Tina | last post by:
How is it possible to designate a textbox so that when the .aspx page is displayed the cursor is already there so the user can just start typing instead of having to click in the textbox with the mouse first? thanks, T
22
4484
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and...
8
5062
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
8
5733
by: nil | last post by:
Hello all, It's urgent... i want to add autocomplete textbox facility in my application like google. as you type it suggests option to the user..i want the same kind of facility...i know i can do only with ajax(xml and javascript) but i want to fetch possible values from database and want to show as the user types in text box.
0
2387
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data...
0
1881
by: =?Utf-8?B?Q29yZXlNY0s=?= | last post by:
I'm working on a TextBox control (in C# using .NET 2.0) that allows fields (like MS Office's mail merge feature). I want the editor to treat the field as though it was a single character. The user shouldn't be able to delete part of the field or select only part of the field. For example, a line might look like: «Image» shot on «Date» at...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
tracyyun
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...
0
5701
agi2029
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...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3248
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...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
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
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
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...

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.