I want to select the available value within the numeric up/down control using c#

enter image description here

and in general if we double click within the control then we get the following(the entire text gets selected colored Blue in BG)

enter image description here

Now my question is How do I achieve this pro-grammatically??


My trails so far :

Focus();

Select();

this doesn't seem to work, any help on this regard would be much appreciated, Thanks..:)

有帮助吗?

解决方案

Select has an overload that takes two int, one for selection start, one for selection length:

myNumericUpDown.Select(0, myNumericUpDown.Text.Length);

其他提示

Do you not just want the .Value property of the control? Or are you trying to get it exactly the way it is formatted in the textbox?

You can get to the TextBox portion of the control through a trick, use the Controls property. Like this:

    var box = (TextBox)numericUpDown1.Controls[1];
    box.SelectAll();
    box.Focus();

This would normally be a bit fragile, but it is 99.9% guaranteed that NumericUpDown is never going to change.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top