自定义textbox控件,实现智能输入数字和点号

代码如下:

 
  
public class TextBoxExtention:TextBox
    {

       
private bool IsHavePoint { getset; }
       
       
protected override void WndProc(ref Message m)//Control.WndProc处理 Windows 消息。 
       {


           
if (m.Msg == 0x0102 && !Char.IsControl((char)m.WParam))
           {
               
//0x0102,字符消息,也称为键盘消息,如果某窗口拥有输入焦点,当用户在应用程序运行时按下一个键时,
               
//系统就会产生一个键盘消息0x0102,告诉此窗口键盘上哪个键被按下了
               if (Char.IsNumber((char)m.WParam) || (Char.Equals((char)m.WParam, '.'&& !IsHavePoint))
               {
                   
base.WndProc(ref m);
               }
               
if (Char.Equals((char)m.WParam, '.'))
               {
                   IsHavePoint 
= true;
               }
               
if (!this.Text.Contains("."))
               {
                   IsHavePoint 
= false;
               }
               
return;
           }         
           
base.WndProc(ref m);
       }
    }

但又一个问题,如果我在最后的一个base.WinProc(ref m)前添加

 if (!this.Text.Contains("."))
               {
                   IsHavePoint 
= false;
               }
vs就卡死了,不知道为什么会这样

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案