Can you provide a code snippets f开发者_运维知识库or this?
Trapping the keystroke isn't enough, the user can also paste using the context menu. This requires trapping the operation at a lower level, you have to catch the WM_PASTE message and prevent it from reaching the native Windows control. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. It does have one flaw, the Paste command isn't disabled on the context menu. No easy fix for that one, you'd have to replace it with your own.
using System;
using System.Windows.Forms;
class NopasteTextBox : TextBox {
protected override void WndProc(ref Message m) {
// Trap WM_PASTE:
if (m.Msg == 0x302) return;
base.WndProc(ref m);
}
}
精彩评论