111,129
社区成员
发帖
与我相关
我的任务
分享 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char value = e.KeyChar;
int key = (int)value;
if (key != 22)
return;
//TODO
}public class MyTextBox : TextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
handled = e.Handled = e.Control && e.KeyCode == Keys.V;
base.OnKeyDown(e);
}
bool handled = false;
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = handled;
if (handled && CtrlVPressed != null) CtrlVPressed(this, e);//触发事件
base.OnKeyPress(e);
handled = false;
}
public event EventHandler CtrlVPressed;
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.V)
{
//下面写代自己的代码
if (Clipboard.ContainsText())
{
this.textBox1.SelectedText = Clipboard.GetText();
}
}
}