469,926 Members | 1,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Cursor position in NumericUpDown control

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 box by 1 if my cursor is in front of the
decimal point. If the cursor is after the decimal point, I want to increment
the value by 0.1. How do I accomplish this? Is there a way to find out the
cusror position in the control relative to decimal point?

Greatly appreciate any help you can provide,

Shridev
Nov 16 '05 #1
1 4523
Shridev,

I don't think that this is possible out of the box. The control doesn't
expose anything about the text that is in the box.

If you were to do it, you would have to take a look at the Cursor class
in the System.Windows.Forms namespace. It has a static property, Position
which gives you the position of the cursor in screen coordinates. Once you
have that, you can pass that point to the PointToClient method on the
numeric up/down control. This will give you the coordinates relative to the
control.

At that point, you are going to have to determine on which side of the
decimal point it is. I would try and use the TextRenderer class in the
System.Windows.Forms namespace (it's a new class in 2.0, and I wouldn't even
think of trying to calculate this stuff manually) and it can tell you the
width of text given a font and the text. You will have to parse apart your
string to get the widths, and then calculate the offsets to see if your
cursor is in the right place.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tantra Veda" <tv***@yahoo.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
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 box by 1 if my cursor is in front of the
decimal point. If the cursor is after the decimal point, I want to
increment
the value by 0.1. How do I accomplish this? Is there a way to find out the
cusror position in the control relative to decimal point?

Greatly appreciate any help you can provide,

Shridev

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Chuck Bowling | last post: by
1 post views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
2 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.