Question

In vb.net I would like to set all numericUpDown (NUD) controls to select their value when they receive focus, like a text box does.

Do I need to write a GotFocus handler for each NUD?

Ta

EDI: I know I can use widthBox.Select(0, widthBox.ToString().Length) to do the selection I just need to be able to apply this to all NUD GotFocus events

Was it helpful?

Solution 2

Project> Add New Item> CustomControl (with name customUpDown).

In solution explorer select view all files and find and open customUpDown.Designer.vb change the line Inherits System.Windows.Forms.Control1 to Inherits System.Windows.Forms.NumericUpDown and save.

View code on the file customUpDown.vb file and add

Private Sub 
customUpDown_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles_
Me.GotFocus 
Me.Select(0, Me.ToString().Length) 
End Sub

OTHER TIPS

You could inherit your own control from a NumericUpDown that has the desired behavior, and use that instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top