472,110 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 4800
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
reply views Thread by leo001 | last post: by

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.