Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

is there any way to zoom using scroll wheel ? i have tried AutoMouseWheel of map control, it works well for the first used custom tool, but once i change the tool, it stops working , i would like to know the reason of this weird behavior.

i don't know if it is possible to catch mouse wheel events in custom tool ? that's seems to be an alternative solution.

Any suggestion or help is welcome :)

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The reason is, because mouse wheel event is enabled for only activated window (focused window). So, when you press the tool, then MapControl lost focus and the tool command (window) will get focus. Here the sample how to set focus on MapControl when you activate the custom tool.

[DllImport("user32.dll")]
static extern IntPtr SetFocus(IntPtr hWnd);

/// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick() {
    // TODO: Add Tool1.OnClick implementation
    IActiveView pActiveView =  m_hookHelper.ActiveView;
    SetFocus((IntPtr)pActiveView.ScreenDisplay.hWnd);
}
share|improve this answer
    
you solution for mouse wheel is better than mine :), thanks –  geogeek May 6 '13 at 12:05

concerning the Pan using the click on mouse wheel

 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
    {
        if (e.button == 4)
        {
            //MapControl map = (MapControl)((ToolbarControl)hookHelper.getHook()).getBuddy();
            display = axMapControl1.ActiveView.ScreenDisplay;

            display.PanStart(display.DisplayTransformation.ToMapPoint(e.x, e.y));

        }

    }

    private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
    {
        if (e.button == 4 && display != null)
        {
            display.PanStop();

            axMapControl1.ActiveView.Refresh();

        }
    }

    private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
    {
        if (e.button == 4 && display != null)
        {
            display.PanMoveTo(display.DisplayTransformation.ToMapPoint(e.x, e.y));

        }
    }

and concerning the zoom using the mouse wheel, i have used the mouse wheel event of the form

void Form1_MouseWheel(object sender, MouseEventArgs e)
    {

       axMapControl1.MapScale += axMapControl1.MapScale * ((e.Delta) / 1200.0f);
       axMapControl1.ActiveView.Refresh();

    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.