MapWinGIS:SampleCode-C Sharp Net:SupportMouseWheel

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

A Map Subclass that enables the Mouse Scroll Event

 // This illustrates creating a sublcass for the ActiveX Map Control that supports MouseWheel events
 // This example code was written by Ted Dunsford on April 29, 2008
 using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Windows.Forms;
 namespace WindowsApplication13
 {
     /// <summary>
     /// This class inherits the basic activeX map control, but exposes the MouseWheel event
     /// </summary>
     public class MouseWheelMap : AxMapWinGIS.AxMap
     {
         public const int WM_PAINT = 0xF;
         public const int WM_LBUTTONDBLCLK = 0x203;
         public const int WM_RBUTTONDBLCLK = 0x204;
         public const int WM_MOUSEWHEEL = 0x20A;
 
         public const int MK_CONTROL = 0x8;
         public const int MK_LBUTTON = 0x1;
         public const int MK_RBUTTON = 0x2;
         public const int MK_MBUTTON = 0x10;
         public const int MK_SHIFT = 0x4;
 
         public event MouseEventHandler mwMouseWheel;
 
         /// <summary>
         /// Overrides the normal WndProc message in order to 
         /// </summary>
         /// <param name="m">The message structure</param>
         protected override void WndProc(ref Message m)
         {
             int xpos = m.LParam.ToInt32() & 65535;
             int ypos = m.LParam.ToInt32() / 65536;
             int MouseKeys = m.WParam.ToInt32() & 65535;
             int Rotation = m.WParam.ToInt32() / 65536;
             int delta = Rotation / 120;
             MouseButtons mb = new MouseButtons();
             switch (MouseKeys)
             {
                 case MK_LBUTTON: mb = MouseButtons.Left;
                     break;
                 case MK_RBUTTON: mb = MouseButtons.Middle;
                     break;
                 case MK_MBUTTON: mb = MouseButtons.Middle;
                     break;
                 default: mb = MouseButtons.None;
                     break;
             }
 
             if (m.Msg == WM_MOUSEWHEEL)
             {
                 OnMwMouseWheel(new MouseEventArgs(mb, 0, xpos, ypos, delta));
             }
 
             base.WndProc(ref m);
         }
 
         /// <summary>
         /// Raises the MouseWheel event
         /// </summary>
         /// <param name="e">A MouseEventArgs</param>
         protected virtual void OnMwMouseWheel(MouseEventArgs e)
         {
             if (mwMouseWheel == null) return;
             mwMouseWheel(this, e);
         }
     }
 }

Using the Class

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Text;
 using System.Windows.Forms;
 
 namespace WindowsApplication13
 {
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
             MouseWheelMap mwMap = new MouseWheelMap();
             mwMap.Parent = this;
             mwMap.Width = this.Width;
             mwMap.Height = this.Height;
             mwMap.Left = 0;
             mwMap.Top = 0;
             mwMap.mwMouseWheel += new MouseEventHandler(mwMap_mwMouseWheel);
         }
 
         void mwMap_mwMouseWheel(object sender, MouseEventArgs e)
         {
             MessageBox.Show(e.Delta.ToString());
         }
 
 
     }
 }


Posted by Ted Dunsford April 29, 2008

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-C_Sharp_Net:SupportMouseWheel"

This page has been accessed 1,805 times. This page was last modified on 29 April 2008, at 16:11.