控制C#中的文本输入只能是数字类型

 

privatevoid NumberAccpter(object sender, KeyPressEventArgs e)
        {
           
int keyValue = (int)e.KeyChar;
           
if ((keyValue >=48&& keyValue <=57) || keyValue ==8|| keyValue ==46)
            {
               
if (sender !=null&& sender is TextBox && keyValue ==46)
                {
                   
if (((TextBox)sender).Text.IndexOf(".") >=0)
                        e.Handled
=true;
                   
else
                        e.Handled
=false;
                }
               
else
                    e.Handled
=false;
            }
           
else
                e.Handled
=true;
        }

posted @ 2012-08-14 17:30  +-/\-+  阅读(307)  评论(0编辑  收藏  举报