views:

42

answers:

1

I'm trying to get the LAT/LON position of the mouse in a Windows Forms app using the browsercontrol and IGEPlugin. Anyone got a clue?

+1  A: 

This isn't too hard if you use the free Winforms Geplugin control librar y- just follow these simple steps

You need to tell the web browser object that you want to listen for mousemove events

 geWebBrowser.AddEventListener(gePlugin.getGlobe(), "mousemove");

Then you need setup some event handlers. The code below should be easy to read. You can determine the lat / long of the mouse cursor from the mouseEvent argument in the DoMouseMove method

geWebBrowser.KmlEvent += GeWebBrowserKmlEvent;


private void GeWebBrowserKmlEvent(object sender, GEEventArgs e)
        {
            // if it is a mouse event
            if (null != sender as IKmlMouseEvent)
            {
                handleKmlMouseEvents((IKmlMouseEvent)sender, e.Data);
            }
            else
            {
                MessageBox.Show(GEHelpers.GetTypeFromRcw(sender));
            }
        }

 private void handleKmlMouseEvents(IKmlMouseEvent mouseEvent, string action)
        {
            string currentTarget = mouseEvent.getCurrentTarget().getType();

            switch (action)
            {
                case "mousemove":
                    {
                        DoMouseMove(mouseEvent);
                        break;
                    }

                case "click":
                    {
                        DoClick(mouseEvent, currentTarget);
                        break;
                    }
                case "mousedown":
                    {
                        DoMouseDown(mouseEvent, currentTarget);
                        break;
                    }
                case "mouseup":
                    {
                        DoMouseUp(mouseEvent);
                        break;
                    }
            }
        }

 private void DoMouseMove(IKmlMouseEvent mouseEvent)
 {

 }
Dominic
link to the controls: http://code.google.com/p/winforms-geplugin-control-library/
Fraser