屏蔽Ctrl+V
情况1:
解决方案1
在WinForm中的TextBox控件没有办法屏蔽CTRL-V的剪贴板粘贴动作,如果需要一个输入框,但是不希望用户粘贴剪贴板的内容,可以改用RichTextBox控件,并且在KeyDown中屏蔽掉CTRL-V键,例子:
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.Control && e.KeyCode==Keys.V)
e.Handled = true;
}
解决方案2
重写WndProc
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
// User clicked close button
this.WindowState = FormWindowState.Minimized;
return;
}
base.WndProc(ref m);
}
屏蔽Ctrl+C
publicclassMyTextBox : TextBox
{
public constintWM_COPY=0x301;
public constintWM_CUT=0x300;
protectedoverride voidWndProc(refMessage m)
{
if(m.Msg==WM_COPY ||m.Msg==WM_CUT)return;//不处理
base.WndProc(refm);
}
}