Search code examples
vb.netnumericupdown

vb.net for all numericUpDown GotFocus


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


Solution

  • 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