由于按键visual basic 2012(OOP方法),空间无法正常工作 [英] Space not working because of keypress visual basic 2012 (OOP method)

查看:122
本文介绍了由于按键visual basic 2012(OOP方法),空间无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2012和SQL Server 2012来制作注册表格。



当我使用按键使我的文本框只允许字母时,键盘上的空格键不起作用。



如何为此编码?



my keypress编码:

i'm using Visual Studio 2012 and SQL Server 2012 to make register form.

When I'm using keypress to make my textbox only allow letter, the space button in my keyboard not working.

How do I make the coding for this?

my keypress coding:

Private Sub txt_namaayah_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_namaayah.KeyPress
       If Not ((e.KeyChar >= "a" And e.KeyChar <= "z") Or e.KeyChar = vbBack) Then e.Handled = True
   End Sub

   Private Sub txt_namaibu_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_namaibu.KeyPress
       If Not ((e.KeyChar >= "a" And e.KeyChar <= "z") Or e.KeyChar = vbBack) Then e.Handled = True
   End Sub

   Private Sub txt_namawali_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_namawali.KeyPress
       If Not ((e.KeyChar >= "a" And e.KeyChar <= "z") Or e.KeyChar = vbBack) Then e.Handled = True
   End Sub


   Private Sub txt_namasiswa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_namasiswa.KeyPress
       If Not ((e.KeyChar >= "a" And e.KeyChar <= "z") Or e.KeyChar = vbBack) Then e.Handled = True
   End Sub

推荐答案

猜测 - 没有你的代码就可以了 - 你正在测试按键以查看它是否是一个有效的字母。这样的东西:

At a guess - and without your code that's all it can be - you are testing the key press to see if it is a valid letter.Something like this:
private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    e.Handled = !((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z'));
    }



或:


Or:

private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    e.Handled = !Char.IsLetter(e.KeyChar);
    }



您需要做的就是扩展允许的字符:


All you need to do is extend the "permitted characters":

private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    e.Handled = !(Char.IsLetter(e.KeyChar) || e.KeyChar == ' ');
    }


这篇关于由于按键visual basic 2012(OOP方法),空间无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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