Click here to Skip to main content
15,611,691 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In the C # windows forms application, how to use the mouse hook to capture mouse scroll wheel to control the googleearth zoom in and out ? Thank you, eh.

1 solution

Why do you think you need a Hook? You just need to handle the event System.Windows.Forms.Control.OnMouseWheel:

MyControl.OnMouseWheel += (sender, eventArgs) => {
    GoogleEarth.ZoomBy(eventArgs.Delta); //or whatever you do for zoom, see below

I see you also want to use C# v.2. In this case, the lambda form will not work. You need to use older syntax:

using System.Windows.Forms; 


MyControl.OnMouseWheel += delegate(object sender, MouseEventArgs eventArgs) {
    GoogleEarth.ZoomBy(eventArgs.Delta); //or whatever you do for zoom, see below

In this form you need explicit declaration of the delegate arguments as the type inference was not yet introduced in C# v.2.

The property Delta here gets a signed value of the wheel rotation which caused the event. For more detail, please see:[^].

Share this answer
Kim Togo 22-May-11 2:58am    
Good answer SA. My 5.
Sergey Alexandrovich Kryukov 22-May-11 3:04am    
Thank you, Kim.
George Hendrickson 26-Apr-12 12:59pm    
How do you capture the mouse wheel while holding down the CTRL key?
Sergey Alexandrovich Kryukov 26-Apr-12 14:52pm    
Capture the key separately using Form.KeyDown Form.KeyUp events and remember the status of this key. The form should have Form.KeyPreview = true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900