首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

textBox1的操作解决方案

2013-07-20 
textBox1的操作键盘操作textBox1,无论是退格键backspace,还是删除键delete,操作之后 textBox1.Text 1,

textBox1的操作
键盘操作textBox1,无论是退格键backspace,还是删除键delete,

操作之后 textBox1.Text = "1",

该如何实现呢?谢谢
[解决办法]

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)8 
[解决办法]
 e.KeyChar == (char)46)
            {
                this.textBox1.Text = "1";
            }
        }

[解决办法]

  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.TextChanged+=new EventHandler(textBox1_TextChanged);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text != "1")
            {
                textBox1.Text = "1";
            }
        }
    }

[解决办法]
textBox1_Changed
{
    if (textBox1.Text == "") textBox1.Text == "1";


}
[解决办法]
搜索消息钩子,或者简单一点如下:

 private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == (Keys.RButton 
[解决办法]
 Keys.MButton 
[解决办法]
 Keys.Back 
[解决办法]
 Keys.Space) 
[解决办法]
 e.KeyCode == Keys.Back)
            {
                this.textBox1.Text = "1111111";
            }
        }

热点排行