char c = (char)e.KeyCode;if (c < '0' || c > '9')
{
   e.Handled = true;
}

解决方案 »

  1.   

    if(!char.IsNumber((char)e.KeyCode))
      e.Handled = True;
      

  2.   

    谢谢思归老大!
    问题解决了。
    可vb.net中的函数就真的没办法调用么?
    还有一个问题再另一个帖子里
    http://community.csdn.net/Expert/topic/3300/3300116.xml?temp=.2778589
    希望老大能多帮帮忙(好容易碰上呢,呵呵)
    多谢了!
      

  3.   

    vb.net中的有些函数是特制的,C#里没有。比如Len,
      

  4.   

    to BearRui(我有点笨,但我很特别,所以我特别笨!) 
    这个方法我开始就试过。不过用错事件了,同时看调试时说(char)e.KeyCode有错误,结果效果没达到还以为不对呢,刚刚试了一次没问题
    最后我是在Keypress事件中用keychar解决的多谢了!
      

  5.   


    char c = System.Convert.ToChar(e.KeyCode);
    if (!System.Char.IsNumber(c))){
      e.Handled = True;
    }
      

  6.   

    To outspaceman(狮子洋) 
    正因为C#中没有所以才想引用vb中的函数呀:)
    像我在开始说得那个调引用的方法就是一个别人说的方法,可惜我没有成功,所以才问思归老大有没有什么办法呢,呵呵:)也谢谢你了!:)
      

  7.   

    VB中的函数C#怎么能调用,如果能互相调用的话那就放到.net framework里去了。
      

  8.   

    yes, you can call VB method
    add a reference to Microsoft.VisualBasic.dll in %WINDIR%\Microsoft.Net\Framework\v1.0.3705or%WINDIR%\Microsoft.Net\Framework\v1.1.4322then in your code, dousing Microsoft.VisualBasic;and then bool b = Information.IsNumeric("123");but I don't think it is good idea to use VB functions instead of FCL
      

  9.   

    To saucer(思归/MVP) 
     就是因为原语言不同么,还是因为别的什么原因老大才不推荐这样用呢?还有:请问老大FCL是什么东东呢?
      

  10.   

    FCL = framework class librarynot just language, Microsoft.VisualBasic namespace contains the classes and modules that constitute the Visual Basic .NET run-time library