0
我的子類的文本框,根據我的需要通過例如從here子類NumericUpDown控件
在相同的方式,我試着子類NumericUpDown控件對他們獲得全選功能和更換,如果點(「」)字符是按下逗號(「,」)字符以適應NumericUpDown控件更適合我的語言環境。
但我不能這樣做,因爲NumericUpDown沒有像文本框一樣的屬性,我希望這兩個控件的行爲方式相同。
在我的代碼兩個問題仍然存在,全選和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
請幫助得到這個工作。
更換炭工程確定,與鍵盤OK選擇但用鼠標選擇不起作用。 –
通過將Me.Text.Length = 0替換爲Me.Text.Length <> 0,正如您所述,使用鼠標選擇(向上)也可以按預期工作。非常感謝你! –
@ user973238我很高興它的工作。感謝接受 :-) – AbZy