怎么使程序运行后Textbox里显示值,比如,运行后要使Textbox里显示1≤key≤4,并且鼠标单击后就没显示了,而你输入的值只能在这范围之内,各位大虾们,帮帮忙哈,谢谢咯

解决方案 »

  1.   

    用textBox1_TextChanged判断下好了
      

  2.   

    随便参考下吧!可能有问题哦!写的也不好!private void Form1_Load(object sender, EventArgs e)
            {
                this.textBox1.Text = "1<=key<=4";
                this.textBox1.Click += new EventHandler(textBox1_Click);
            } void textBox1_Click(object sender, EventArgs e)
            {
                this.textBox1.Text = null;
                this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
            }
            void textBox1_TextChanged(object sender, EventArgs e)
            {
                int s = int.Parse(this.textBox1.Text);
                {
                    if (s >4||s < 0)
                    {
                        if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            this.textBox1.Text = "1"                    }                                   
                    }
                 }
             }
      

  3.   

    private void Form1_Load(object sender, EventArgs e) 
            { 
                this.textBox1.Text = "1 <=key <=4"; 
                this.textBox1.Click += new EventHandler(textBox1_Click); 
            } void textBox1_Click(object sender, EventArgs e) 
            { 
                this.textBox1.Text = null; 
                this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged); 
            } 
            void textBox1_TextChanged(object sender, EventArgs e) 
            { 
                int s = int.Parse(this.textBox1.Text); 
                 if (s >4||s < 0) 
                    { 
                        if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 
                        { 
                            this.textBox1.Text = "1";                    }                                  
                    } 
              } 
      

  4.   

    设置步骤:
    1:
      textbox的Maxlength属性=1
          textbox的text属性="1≤key≤4"
    2:textBox_Enter的事件中写如下代码:
           
                this.textBox2.Text = "";
    3:
     private void textBox_KeyPress(object sender, KeyPressEventArgs e)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 53)&& e.KeyChar != 8 && e.KeyChar != 46)
                {
                    e.Handled = true;
                }
           }
      

  5.   

    设置步骤:
     1:textbox 的maxlength属性:1
             textbox 的text属性:1≤key≤4 2:private void textBox_Enter(object sender, EventArgs e)
            {
                this.textBox2.Text = "";        }
    3:private void textBox_KeyPress(object sender, KeyPressEventArgs e)
            {
                this.textBox.Text = "";
                if ((e.KeyChar < 48 || e.KeyChar > 53) && e.KeyChar != 8 && e.KeyChar != 46)
                {
                    e.Handled = true;
                }
            }