1

我正在开发这个用户控件,它需要我覆盖WndProc控件的父级[实际上是一个 Windows 窗体],我很难过。

通常,我可以将用户放在表单上并手动覆盖表单WndProc。由于我的整个开发团队以及我现在不知道的其他人可能正在使用它,我认为我最好从 UserControl 覆盖。

有谁知道我怎么能做到这一点?我的首选语言是 VB.NET 和 C#。

4

1 回答 1

3

您可以尝试NativeWindow,通过this.FindForm().

那是,

public class MyListener : NativeWindow
{
     public MyListener(UserControl myControl)
     {
         this.AssignHandle(myControl.FindForm().Handle);
     }

     protected override void WndProc(ref Message m)
     {
          // do stuff
          base.WndProc(ref m);
     }

     // dispose, etc.
}

以这种方式继承NativeWindow将使您拦截 Windows 消息。

祝你好运!

于 2010-08-21T22:09:16.363 回答