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

How to set all numericupdown auto-select text when got focus?

My win-form have many numericupdown controls to applied. But numericupdown
control don't like textbox, text box control can automatic selected text
when got focus. Is there any method can let me set all numericupdown
autoselect text when gotfocus?
Dec 25 '05 #1
3 30022
Hi ABC,
My win-form have many numericupdown controls to applied. But
numericupdown control don't like textbox, text box control can automatic
selected text when got focus. Is there any method can let me set all
numericupdown autoselect text when gotfocus?


I'm not exactly sure if I understood you 100% clearly, but I assume you want
to have a NumericUpDown to select the whole value (text) when one tabs into
the control, like the TextBox control would function.

The NumericUpDown control has an (overloaded) method called Select, to which
you can pass in two integers: the index of the first character to be
selected, and then the number of characters to select. To select all text,
you would start from index zero, and the length would then be the number of
characters in the value.

If you call the Select method in the Enter event of the NumericUpDown
control for example like this, you should be able to emulate the TextBox
functionality:

-----------------------------
private void numericUpDown1_Enter(object sender, EventArgs e)
{
numericUpDown1.Select(0, numericUpDown1.ToString().Length);
}
-----------------------------

Note that the NumericUpDown control doesn't have a Text property, since the
Value property is used instead. Also, if you know that there will be, say,
maximum of three numbers in the value (maximum integer value 999), you could
also always call Select(0,3). It doesn't hurt if there are less than three
numbers in the value currently.

Hope this helps! Merry Christmas as well!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 26 '05 #2
Yes, you right, but there are many numericupdown controls (over 300), is
there any good method?
"Jani Järvinen [MVP]" <ja***@removethis.dystopia.fi> ¼¶¼g©ó¶l¥ó·s»D:Oy**************@TK2MSFTNGP14.phx.g bl...
Hi ABC,
My win-form have many numericupdown controls to applied. But
numericupdown control don't like textbox, text box control can automatic
selected text when got focus. Is there any method can let me set all
numericupdown autoselect text when gotfocus?


I'm not exactly sure if I understood you 100% clearly, but I assume you
want to have a NumericUpDown to select the whole value (text) when one
tabs into the control, like the TextBox control would function.

The NumericUpDown control has an (overloaded) method called Select, to
which you can pass in two integers: the index of the first character to be
selected, and then the number of characters to select. To select all text,
you would start from index zero, and the length would then be the number
of characters in the value.

If you call the Select method in the Enter event of the NumericUpDown
control for example like this, you should be able to emulate the TextBox
functionality:

-----------------------------
private void numericUpDown1_Enter(object sender, EventArgs e)
{
numericUpDown1.Select(0, numericUpDown1.ToString().Length);
}
-----------------------------

Note that the NumericUpDown control doesn't have a Text property, since
the Value property is used instead. Also, if you know that there will be,
say, maximum of three numbers in the value (maximum integer value 999),
you could also always call Select(0,3). It doesn't hurt if there are less
than three numbers in the value currently.

Hope this helps! Merry Christmas as well!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

Dec 26 '05 #3
Hello!
Yes, you right, but there are many numericupdown controls (over 300), is
there any good method?


Good question. The easiest way to solve this issue is to point all the Enter
event handlers of those NumericUpDown's to a single event handler.

That is, if you are in Visual Studio, you can double-click an event in the
Properties window to create an event handler for the selected control. In
all other NumericUpDown controls, you would not double-click the value
column in the Properties window, but instead select an existing event
handler from the list.

In code, this would look like the following:

------------------------
numericUpDown1.Enter += new System.EventHandler(numericUpDown1_Enter);
numericUpDown2.Enter += new System.EventHandler(numericUpDown1_Enter);
------------------------

Note how both Enter event handlers now point to the same code, i.e. the
numericUpDown1_Enter method.

The next question is obviously how to be able to determine which
NumericUpDown is in question. You can use code similar to the following:

------------------------
private void numericUpDown1_Enter(object sender, EventArgs e)
{
(sender as NumericUpDown).Select(0, 10);
}
------------------------

As I said, this is probably the easiest solution, but not the most elegant
one. If you have 300 controls (hopefully not on the same form!) I would
suggest developing a custom control that inherits from NumericUpDown, and
implements the functionality you want without writing custom event handlers.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 26 '05 #4

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

Similar topics

0
by: Koert | last post by:
Hi, In the NumericUpDown control I have to detect that Tab was pressed so I have overroden the PreProcessMessage function. In for example the DateTimePicker this works fine but not in the...
2
by: Patrick Blackman | last post by:
Can anyone tell me how to get the numericupdown control to support themes?
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...
2
by: ReMEn | last post by:
Didn't find much documentation on value formatting on a NumericUpDown control. is it possible to separate numbers by a special character. For example, If I wanted to display an option to change a...
0
by: Koert | last post by:
Hi In the NumericUpDown control I have to detect that Tab was pressed so I have inherited the NumericUpDown and overroden the PreProcessMessage function. In the DateTimePicker (for example) this...
0
by: stx | last post by:
Hope some one can help, but I need to create a resizable numericUpDown control. This I have created currently using a textbox and a user control implemented using the ControlPaint.DrawScrollButton...
2
by: bnob | last post by:
It is possible to format the numeric value of the NumericUpDown control For example : display numbers in 2 digits, instead of 1 display 01, 0 -> 00 , 9 -> 09 Any idea -- Ceci est une...
5
by: Len Weltman | last post by:
I am trying to pass a NumericUpDown object into a class method using Visual Studio 2005, but the control type is not found in Intellisense and the type declaration is flagged as an error. Here...
16
by: tommaso.gastaldi | last post by:
Hello, A probably dumb question... does anyone know hot to avoid that if one keep the mouse pressed on an arrow of the numericUpDown it continues to fire events (it uses evidently a timer) ?...
1
by: =?Utf-8?B?R3VzIENodWNo?= | last post by:
How do I set the Maximum values of a NumericUpDown Control? If OptionBox TermsMonths.Checked = True Then Control.Maximum() = 360 Else Control.Maximum() = 30 -- Thank You Gus Chuchanis
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.