سؤال

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

هل كانت مفيدة؟

المحلول 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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top