允许用户使用键码进行一些按键操作 [英] allow user some keypress with keycode

查看:89
本文介绍了允许用户使用键码进行一些按键操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我希望能够只输入数字,小键盘,减号键,删除键和空格和小数。

 i want to be able to type only numbers, ,numpad, minus key, delete key and backpace and decimal.

因为某些原因它不起作用。我只能在字母上面输入数字..

for somereason it does not work. i can only type the numbers above letters..

会对某些知识感到满意:)

would be happy for some knowladge :)

我知道这种方法可能不是你的好感但是这种方式我不明白..  

i know this method is probably not your favor but this way i undestand..  

  If (e.KeyCode >= Keys.D0 And e.KeyCode <= Keys.D9 And e.Modifiers <> Keys.Shift) Or (e.KeyCode >= Keys.NumPad0 And e.KeyCode <= Keys.NumPad9) And e.KeyCode <> Keys.Left And e.KeyCode <> Keys.Right And e.KeyCode <> Keys.Back And e.KeyCode <> Keys.Decimal And e.KeyCode <> Keys.Delete And e.KeyCode <> Keys.OemMinus Then
            e.SuppressKeyPress = False
        Else
            e.SuppressKeyPress = True



        End If

谢谢,

Noam。

推荐答案

你好,



看看这对你有帮助吗? b $ b
Hello,

See if this helps to you
    Private Sub TextBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Try
            If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." And Not e.KeyChar = "-" Then
                e.Handled = True
            End If
        Catch ex As Exception
            Dim errormsg As String = String.Empty
            errormsg = ex.ToString()
        End Try
    End Sub








这篇关于允许用户使用键码进行一些按键操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆