首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NumericUpDown控件的子类化

NumericUpDown控件的子类化
EN

Stack Overflow用户
提问于 2013-02-03 21:24:20
回答 1查看 423关注 0票数 0

我根据自己的需要从here中通过示例派生了一个textbox

同样,我尝试对NumericUpDown控件进行子类化,以获得它们的selectAll功能,并替换if point (".")字符被压成逗号(",")字符,以适应更适合我的语言环境的NumericUpDown控件。

但我不能这样做,因为NumericUpDown不像textbox那样具有相同的属性,我希望这两个控件以相同的方式运行。

在我的代码中仍然存在两个问题,SelectAll和SelectionLength:

代码语言:javascript
复制
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

请帮我把它弄好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-03 21:37:26

要检查长度并选择所有文本,请尝试以下命令:

代码语言:javascript
复制
If Not Me.alreadyFocused AndAlso Me.Text.Length = 0 Then 'Though I suspect it should be <> 0

   Me.alreadyFocused = True
   Me.Select(0, Me.Text.Length)

End If

对于字符替换,试试这个(未测试的):

代码语言:javascript
复制
If keyevent.KeyChar = "."c Then
      keyevent.Handled = True
      SendKeys.Send(",")
End If
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14672944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档