开发者

C# Passing WndProc Messages from a form to another form

I'm working on a C# application with two Windows forms. Both forms are full screen and one form sits on top of the other form as a transparent overlay. The bottom form contains a web browser (also full screen). I'm tracking touch input on the transparent overlay form in order to capture gestures and draw buttons and other controls on the screen. What I need to do is to send all the windows messages that the overlay form gets in its WndProc function to the form开发者_开发问答 below (or the web browser control in the form since that's basically all the lower form is used to contain).

Basically I just need to deal with the gestures on the overlay, all the mouse messages need to still transfer to the web browser to provide certain functionality.

I've tried the naive method of just calling the lower form's WndProc method given the message from the overlay. (And similarly I've tried passing it further to the WndProc of the browser control window). Neither of these methods works. I've also tried simply swapping the HWnd parameter of the Message object to be the handle of the lower form/browser while attempting this and that has also not worked.

So, would anyone be able to think of more methods to try, or possibly the correct method of passing windows messages between forms?

Thanks, Alex


How about create one master form, and let these two forms be the child forms. Delegate events from the child forms to master, and let master process whatever events you want to process.


var topForm = new Form1(); // top form
var browserForm = new Form2(); // bottom form with webbrowser control

add MouseClick event to Form1

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
     browserForm.DoClick(e.X, e.Y);
}

create custom WebBrowserEx control to process mouse click events and add this control to Form2

namespace WindowsFormsApplication1
{
    public class WebBrowserEx: System.Windows.Forms.WebBrowser
    {
        public void DoClick(int x, int y)
        {
            base.OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, x, y, 0));
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜