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";
}
}
}
}
[解决办法]
搜索消息钩子,或者简单一点如下:
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";
}
}