Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WinProc和重写on-paste方法_C#_Winforms_Winapi - Fatal编程技术网

C# WinProc和重写on-paste方法

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

我试图使用以下方法覆盖winform textbox的onpaste方法:

当粘贴发生时,我不希望windows处理它,我希望我的代码能够处理它。因此,我做了以下工作:

        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
,而不是直接调用事件,以便派生类可以控制功能。

看起来您甚至还没有尝试过它?我已经尝试过了,但只是想知道它是否有什么问题