سؤال

I'm working with GMap in c#. When I click on the map I whant to get the location on the screen from where I'm clicking. I have a map controller that is called myMap. When I click on the map an event is triggered called myMap_Click(object sender, MouseEventArgs e). If I place an object, in my case a custom form, on the location e.X, e.Y it wont be placed where I click on the screen.

My goal is to desplay a form where I click on the map. I dont care if it follows coordinate if I pan the map or zoom. For now I just want a custom form on the position I click.

How can I get the screen location when I click on the map contoll?

Regards!

هل كانت مفيدة؟

المحلول

It's actually pretty simple!

private void myMap_Click(object sender, MouseEventArgs e)
{
    using (Form customForm = new Form())
    {
        customForm.StartPosition = FormStartPosition.Manual;
        customForm.DesktopLocation = MainMap.PointToScreen(e.Location);
        customForm.ShowDialog();
    }
}        

Obviously replace "Form customForm" parts with your equivalents.

نصائح أخرى

Well you can use this also

gMapControl1.MouseClick += new MouseEventHandler(map_mouseCLick);

private void map_mouseCLick(object sender, MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) {
            var point = gMapControl1.FromLocalToLatLng(e.X, e.Y);
            double lat = point.Lat;
            double lon = point.Lng;
            //this the the values of latitude in double when you click 
            double newPointLat = lat;
            //this the the values of longitude in double when you click 
            double newPointLong = lon;
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top