// BTN / CLICK / DOUBLE CLICK / ... private void ChooseCityMap_MouseDown(object sender, MouseEventArgs e) { // rewrite indexes lookAtPrevCityIndex = lookAtCurrentCityIndex; lookAtCurrentCityIndex = StartCityIndex; // find the closest city to the click CityModel.City pointer = new CityModel.City(e.X, e.Y); double minDistance = double.MaxValue; for (int i = 0; i < Cities.Length; ++i) { double cutDistance = CityModel.distance(Cities[i], pointer); if (minDistance > cutDistance) { minDistance = cutDistance; lookAtCurrentCityIndex = i; } } // redraw cities into their color DrawCity(Cities[lookAtPrevCityIndex], CityRedPen); DrawCity(Cities[lookAtCurrentCityIndex], CityBluePen); // set city index in UpDown Control StartCityIndex = lookAtCurrentCityIndex; }
private void DrawCity(CityModel.City city, Pen pen) { // -1 because offset graphic.DrawEllipse(pen, city.X - 1, city.Y - 1, 2, 2); }