C# WinProc和重写on-paste方法
我试图使用以下方法覆盖winform textbox的onpaste方法: 当粘贴发生时,我不希望windows处理它,我希望我的代码能够处理它。因此,我做了以下工作:C# WinProc和重写on-paste方法,c#,winforms,winapi,C#,Winforms,Winapi,我试图使用以下方法覆盖winform textbox的onpaste方法: 当粘贴发生时,我不希望windows处理它,我希望我的代码能够处理它。因此,我做了以下工作: if (m.Msg == WM_PASTE) { var evt = Pasted; if (evt != null) { evt(this, new ClipboardEventArgs(C
if (m.Msg == WM_PASTE)
{
var evt = Pasted;
if (evt != null)
{
evt(this, new ClipboardEventArgs(Clipboard.GetText()));
}
}
else
{
base.WndProc(ref m);
}
这是让win32代码不处理粘贴的安全方法,还是我没有看到某些情况?您可能应该使用此模式定义粘贴的事件:
public event ClipboardEventHandler Pasted;
protected virtual void OnPasted(ClipboardEventArgs e)
{
if (Pasted != null)
Pasted(this, e);
}
然后调用
OnPasted
,而不是直接调用事件,以便派生类可以控制功能。看起来您甚至还没有尝试过它?我已经尝试过了,但只是想知道它是否有什么问题