We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Is there a way to capture the mouse events of objects on a form

Thread ID:

Created:

Updated:

Platform:

Replies:

12582 Apr 2,2004 11:19 AM Apr 14,2004 09:53 AM Windows Forms 3
loading
Tags: FAQ
Ryan Milligan
Asked On April 2, 2004 11:19 AM

Hello, How do I handle the mouse events of controls on a form similar to how the keyboard events are processed then the form's keypreview property is set to true? Thanks, Ryan

Praveen Ramesh
Replied On April 8, 2004 09:24 AM

You can listen to the control''s mouse messages through their MouseUp, MouseDown, etc. events as you probably know already. But, those events are fired after they get processed by the control itself. To "preview" these events, you could set up a filter in your Form by implementing the IMessageFilter interface. See .net class ref for that interface. -Praveen

Ryan Milligan
Replied On April 8, 2004 12:22 PM

Yes, this is what I am looking for. I have a form with an axwebbrowser control which does not have a click event. I need to be able to recognize when the xbuttons have been clicked so I can call the back() and forward() methods of the browser. Could anyone please provide an example of how this can be accomplished.

Anthon Ryan Milligan
Replied On April 14, 2004 09:53 AM

I figured it out using the information you provided. It works great. Below is my code: Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim filter As New MyFilter() filter.frm = Me Application.AddMessageFilter(filter) End Sub Public Class MyFilter Implements IMessageFilter 'gets the left mouse button messages Public frm As frmMain Public Const WM_XMOUSEDOWN As Integer = 523 Public Const WM_XMOUSEUP As Integer = 524 Public Const WM_XMOUSEDBL As Integer = 525 Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage If m.Msg = WM_XMOUSEDOWN Or m.Msg = WM_XMOUSEUP Then frm.frmMain_MouseUp(frm.ActiveBrowser, New System.Windows.Forms.MouseEventArgs(frm.MouseButtons, 1, frm.MousePosition.X, frm.MousePosition.Y, 0)) Return (True) End If Return (False) End Function End Class

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;