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/