我正在尝试将 ac# 程序与 GMap 放在一起,我希望鼠标显示在屏幕底部的坐标。我在表单中添加了一个 OnMouseMove 方法,并且我确实得到了坐标,但前提是鼠标不在地图本身上方。如果鼠标在地图上,它不会响应。我对 c# 相当陌生,所以我可能遗漏了一些相当简单的东西。有任何想法吗?下面是我现在正在使用的代码。
public partial class Form1 : Form
{
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
base.OnMouseMove(e);
if(e.Button == MouseButtons.Left)
{
int itest=2;
}
double X = mapexplr.FromLocalToLatLng(e.X, e.Y).Lng;
double Y = mapexplr.FromLocalToLatLng(e.X, e.Y).Lat;
string longitude = X.ToString();
string latitude = Y.ToString();
LongStrip.Text = longitude;
LatStrip.Text = latitude;
}
GMapOverlay overlayOne;
public Form1()
{
InitializeComponent();
}
private void mapexplr_Load(object sender, EventArgs e)
{
//initialisation de notre map
mapexplr.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
mapexplr.Position = new PointLatLng(35.571458, -85.547961);
mapexplr.DragButton = MouseButtons.Left;
mapexplr.SetCurrentPositionByKeywords("Tunisia");
mapexplr.MapProvider = GMapProviders.BingMap;
mapexplr.MinZoom = 3;
mapexplr.MaxZoom = 17;
mapexplr.Zoom = 5;
mapexplr.Manager.Mode = AccessMode.ServerAndCache;
//ajout des overlay
overlayOne = new GMapOverlay(mapexplr, "OverlayOne");
//ajout de Markers
overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(36.657403, 10.327148)));
//ajout de overlay à la map
mapexplr.Overlays.Add(overlayOne);
}
}