private LegendsOfKesmaiSurvival.Services.Business.Maps.MapTile GetTileFromPoint(System.Drawing.Point point) { if (_map == null) { return(null); } //Convert the point on the control to a point on the map's image taking into consideration the current zoom level and scroll position. int x = (int)(-(this.AutoScrollPosition.X - point.X) / GetZoomFactor()); int y = (int)(-(this.AutoScrollPosition.Y - point.Y) / GetZoomFactor()); //Search for a tile that has a rectangle that contains the point. LegendsOfKesmaiSurvival.Services.Business.Maps.MapTile tile = _map.Tiles.Find(delegate(LegendsOfKesmaiSurvival.Services.Business.Maps.MapTile search) { Rectangle tileRectangle = new Rectangle(new Point(search.Location.X * _map.TileWidth, search.Location.Y * _map.TileHeight), _map.TileSize); return(tileRectangle.Contains(new Point(x, y))); }); return(tile); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.SelectedTile = GetTileFromPoint(e.Location); }