现在有4个textBox.我将要在里面填写IP地址。eg:192.168.1.1
我需要限制textBox中只能输入数字 并且 当按"."时,会自动给下一个textBox焦点。
请问应该怎么实现。
是不是在KeyDown事件中写啊?

解决方案 »

  1.   

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar=='.') 
    {
    textBox2.Focus();
    }
    }但是不知道怎么不让点显示出来,只想出textBox1_TextChanged里可以遇到点就删掉
    有没办法当输入点的时候,直接丢弃掉,不进输入框
    请高手解释
      

  2.   

    if(e.KeyChar=='.') 
    { TextBox t=sender as TextBox;
    t.Text=t.Text.SubString(0,t.Text.IndexOf("."));//删除自身,可以不?
    textBox2.Focus();
    }
      

  3.   

    楼上的那个好像不行,keypress的时候,点还没进去,所以会出现找不到点的异常
    这样是可以的
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
        if(textBox1.Text.Substring(textBox1.Text.Length-1,1)==".") 
    {
        textBox1.Text=textBox1.Text.Substring(0,textBox1.Text.IndexOf("."));
        textBox2.Focus();
    }
    }
      

  4.   

    哪位高手快告诉我
    我的问题:
    1。限制输入
    2。按下".",后自动给textBox2焦点,并且textBox1中没有"."
      

  5.   

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar=='.') 
    {
                      e.Handled = true;//加上这句就可以限制输入了
    textBox2.Focus();
    }
    }
      

  6.   


    _TextChanged:

    if(te1.Text.IndexOf(".")>-1)
    {
    te1.Text.Substring(0,te1.Text.IndexOf("."));
    te2.focus();
    }