473,405 Members | 2,185 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,405 software developers and data experts.

Cursor Position in KeyPressEvent

I have a TextBox that I am putting some conditions on, such as restricting
the number of decimal places that the user can enter. I have been using the
KeyPress event, which allow me to examine the current text and prevent
inappropriate keys from being pressed. But I can not figure out how to
determine where in the text the text cursor is. For example, a digit key
might be allowed before the decimal place, but not allowed after, but I can
not determine where the key they pressed is going to be placed, there does
not appear to be a TextBox member that provides this information. Is there
one? Or can it be done another way? Thanks.

May 18 '06 #1
4 2132
Richard MSL wrote:
I have a TextBox that I am putting some conditions on, such as restricting
the number of decimal places that the user can enter. I have been using the
KeyPress event, which allow me to examine the current text and prevent
inappropriate keys from being pressed. But I can not figure out how to
determine where in the text the text cursor is. For example, a digit key
might be allowed before the decimal place, but not allowed after, but I can
not determine where the key they pressed is going to be placed, there does
not appear to be a TextBox member that provides this information. Is there
one? Or can it be done another way? Thanks.

Try TextBox.SelectionStart

Cheers
JB
May 19 '06 #2
Hi Richard,

Thank you for posting.

Would you tell me what the "decimal place" means?

There's a SelectionStart property of the TextBox, which you can use to get
or set the starting point of text selected in the text.

If you know the position the text cursor might be placed, you could use the
SelectionStart property of the TextBox to put the text cursor to the
desired place.

Hope this is helpful to you.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

May 19 '06 #3
Thanks SelectionStart was exactly what I was looking for. By the decimal
place I meant the ".", I needed to know whether the cursor was to the left or
right of the "." to know whether more numerals were allowed. Thanks again.
"Linda Liu [MSFT]" wrote:
Hi Richard,

Thank you for posting.

Would you tell me what the "decimal place" means?

There's a SelectionStart property of the TextBox, which you can use to get
or set the starting point of text selected in the text.

If you know the position the text cursor might be placed, you could use the
SelectionStart property of the TextBox to put the text cursor to the
desired place.

Hope this is helpful to you.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

May 19 '06 #4
Hi Richard,

You're welcome!

If you have any other questions or need anything else, please don't
hesitate to contact us. It is always our pleasure to be of assistance.

Have a nice day!

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

May 22 '06 #5

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

Similar topics

3
by: PeP | last post by:
Good morning, I have a form containing a text-area, I'd like to know if it exists a function that, when I activate an event, returns the position of the cursor in the text-area. For example, I...
1
by: Dan H. | last post by:
Hello, I want to try to retrieve the cursor position x and y relative to the form the cursor is over. The way I am doing it now is: 1. Retrieve the left and top position of the form relative...
1
by: Tantra Veda | last post by:
Hello C# gurus, I have a question about finding cursor position in NumericUpDown control. On my form I have a numericUpDown control with 2 decimal places. I want to increment value in the numeric...
1
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...
1
by: Paul | last post by:
Hi all, I am making a DirectInput application wich must report correctly the cursor position in windowed mode (it means it has to be the same as Microsoft Window´s cursor position). First of...
22
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...
1
by: jobs | last post by:
I'm trying to understand this and don't get it... I found some code that looks like it's going to work if I can make sense of how to position the div. The code displays a div with some data...
4
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through...
4
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
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...
0
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...
0
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,...

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.