【发布时间】:2013-02-03 13:24:20
【问题描述】:
我根据自己的需要从here 举例子类化了一个文本框
以同样的方式,我尝试继承 NumericUpDown 控件以获取它们的 selectAll 功能,并将如果点 (".") 字符按下为逗号 (",") 字符以适应更适合我的语言环境的 NumericUpDown 控件。
但我不能这样做,因为 NumericUpDown 没有像文本框那样的相同属性,我希望这两个控件的行为方式相同。
在我的代码中仍然存在两个问题,SelectAll 和 SelectionLength:
Option Explicit On
Option Strict On
Public Class xNumericUpDown
Inherits NumericUpDown
Private alreadyFocused As Boolean
Protected Overrides Sub OnLeave(ByVal e As EventArgs)
MyBase.OnLeave(e)
Me.alreadyFocused = False
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
MyBase.OnGotFocus(e)
If MouseButtons = MouseButtons.None Then
Me.SelectAll() ' HOW TO MAKE SELECTALL SUB FOR NUMERICUPDOWN?
Me.alreadyFocused = True
End If
End Sub
Protected Overrides Sub OnMouseUp(ByVal mevent As MouseEventArgs)
MyBase.OnMouseUp(mevent)
If Not Me.alreadyFocused AndAlso Me.SelectionLength = 0 Then ' HOW TO CHECK SELECTIONLENGTH FOR NUMERICUPDOWN?
Me.alreadyFocused = True
Me.SelectAll() ' HOW TO MAKE SELECTALL SUB FOR NUMERICUPDOWN?
End If
End Sub
Protected Overrides Sub OnKeyPress(ByVal keyevent As KeyPressEventArgs)
MyBase.OnKeyPress(keyevent)
If keyevent.KeyChar = "." Then
keyevent.KeyChar = CChar(",")
End If
End Sub
End Class
请帮助完成这项工作。
【问题讨论】:
标签: vb.net