code for scroll wheel in winform demo

May 2, 2009 at 11:12 PM

Just a brief snippet to help out.

// MainForm
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(MainForm_MouseWheel);

void MainForm_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Delta > 0)
        {
            if (trackBar1.Value != trackBar1.Maximum)
                trackBar1.Value++;
        }
        else if (e.Delta < 0)
        {
            if (trackBar1.Value > trackBar1.Minimum)
                trackBar1.Value--;
        }
    }
Coordinator
May 3, 2009 at 12:04 PM
done! thx
May 12, 2009 at 8:44 AM

Maybe something to implement in the core? And using a new property UseWheelMouse?

But I think this code is incomplete. In the trackbar ValueChanged I added the following two lines:

// Position the center at the cursor
RectLatLng area = MainMap.CurrentViewArea;
MainMap.CurrentPosition = new PointLatLng(area.Lat - area.HeightLat / 2, area.Lng + area.WidthLng / 2);

I like to implement ghchinoy suggestion, but want to change the CurrentPosition based on the mouse position. So you zoom in on the area the cursor points at. This is the same as clicking first and then zoom.

In the core I see the following code, but can't use it outside:

SetCurrentPositionOnly(e.X - Core.renderOffset.X, e.Y - Core.renderOffset.Y);

Is there a method that gets the LatLong from screen coordinates?

Frank

Coordinator
May 12, 2009 at 11:24 AM

yes, i use that technique in my own project too, just simply in OnMouseMove event use function public PointLatLng FromLocalToLatLng(int x, int y) and set position by public void SetCurrentPositionOnly(PointLatLng point) so when you zoom center position will be where mouse was before, additionaly i move mouse pointer to the center of the control(btw it needs native invoke stuff)

May 12, 2009 at 12:15 PM

Ok, thanks. That works.

I think it is best to do this only at zooming in.

Maybe something to implement in the core? And using a new property UseWheelMouse?

Coordinator
May 12, 2009 at 1:00 PM

something? ;}

May 12, 2009 at 1:12 PM

I don't get these smilies. Is there a translation list?

What I mean here: is it possible to implement a published property called UseWheelMouse in the core DLL? If it is true, the core will handle the zoom as described above.

Coordinator
May 12, 2009 at 1:18 PM

hm...

Coordinator
May 12, 2009 at 2:04 PM

done!