选择All All进入NumericUpDown控件

时间:2013-10-19 12:36:03

标签: vb.net

There are people尝试在输入文本框时解决此类问题。他们或多或少成功地解决了这个问题 我试图用NumericUpDown控件做同样的事情,通过子类化它很不成功 这是我的代码:

Public Class xNumericUpDown
Inherits NumericUpDown

Private _focused As Boolean

Protected Overrides Sub OnEnter(ByVal e As EventArgs)
    MyBase.OnEnter(e)
    If MouseButtons = MouseButtons.None Then
        Me.Select(0, Me.Text.Length)
        _focused = True
    End If
End Sub

Protected Overrides Sub OnLeave(ByVal e As EventArgs)
    MyBase.OnLeave(e)
    _focused = False
End Sub

Protected Overrides Sub OnMouseUp(ByVal mevent As MouseEventArgs)
    MyBase.OnMouseUp(mevent)
    If Not _focused Then
        If Me.Text.Length = 0 Then
            Me.Select(0, Me.Text.Length)
        End If
        _focused = True
    End If
End Sub
End Class

这通过键盘输入选择全部,但在用鼠标选择控件时不起作用。

任何帮助解决这个问题都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可能会踢自己,但尝试将代码更改为:

If Me.Text.Length > 0 Then
  Me.Select(0, Me.Text.Length)
End If