473,386 Members | 1,924 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,386 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 30043
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.