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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





12582 Apr 2,2004 04:19 PM UTC Apr 14,2004 01:53 PM UTC WinForms 3
Tags: FAQ
Ryan Milligan
Asked On April 2, 2004 04:19 PM UTC

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 01:24 PM UTC

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 04:22 PM UTC

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 01:53 PM UTC

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


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon