473,554 Members | 3,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 30094
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().Leng th);
}
-----------------------------

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***@removethi s.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***@removeth is.dystopia.fi> ¼¶¼g©ó¶l¥ó·s»D: Oy************* *@TK2MSFTNGP14. phx.gbl...
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().Leng th);
}
-----------------------------

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***@removethi s.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.EventHan dler(numericUpD own1_Enter);
numericUpDown2. Enter += new System.EventHan dler(numericUpD own1_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***@removethi s.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
1918
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 NumericUpDown. The debugger does not stop in the PreProcessMessage function. Is this a bug in the NumericUpDown control? thanks, Koert
2
1586
by: Patrick Blackman | last post by:
Can anyone tell me how to get the numericupdown control to support themes?
1
5077
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 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...
2
1266
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 person's height in a NumericUpDown, I would not want them to see 62, I'd want them to see 6'2" (6-Foot-Two). Is this even possible? Thankyou,
0
1420
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 works fine but not in the NumericUpDown. It seams that the debugger does not access the PreProcessMessage function. Is this a bug in the NumericUpDown...
0
2172
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 method These currently seems fine, the problem I have is how would I go about implementing a method that would continue incrementing/decrementing the...
2
3693
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 signature automatique de MesNews. Site : http://www.mesnews.net
5
2168
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 is a code sample (which doesn't work): *** Begin code ***
16
9162
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) ? I want 1 event for each click, and no timer activation. I have tried using disable within the handler but does not work.
1
1528
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
7596
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8039
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7887
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5152
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1130
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
838
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.