/// <summary>
 /// Handles the OnMouseDown event of the Tile control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
 private void Tile_OnMouseDown(object sender, MouseEventArgs e)
 {
     PictureBox picBox = (PictureBox)(sender);
     UnselectTiles(view.paEditor);
     tileBeingDragged = GetTileAssociatedWithPictureBox(picBox);
     tileBeingDraggedPictureBox = picBox;
 }
 /// <summary>
 /// Unselects the tiles.
 /// </summary>
 /// <param name="form">The form.</param>
 private void UnselectTiles(Control form)
 {
     foreach (Control cControl in form.Controls)
     {
         if (cControl is PictureBox)
         {
             ((PictureBox)cControl).BorderStyle = BorderStyle.FixedSingle;
         }
     }
     view.statusStripTileX.Text = "";
     view.stripStatusTileY.Text = "";
     view.propGrid.SelectedObject = null;
     selectedTile = null;
 }
            /// <summary>
            /// Handles the MouseUp event of the Tile control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
            private void Tile_MouseUp(object sender, MouseEventArgs e)
            {
                PictureBox picBox = (PictureBox)(sender);
                //Behave like a click if its the same tile. Else do drag & drop.
                if (picBox == tileBeingDraggedPictureBox)
                {
                    if (selectedTile != null && IsSelectedTile(picBox))
                    {
                        UnselectTiles(view.paEditor);
                    }
                    else
                    {
                        if (e.Button == MouseButtons.Right)
                        {
                            int x = GetVisualTileCoordinates(picBox)[1];
                            int y = GetVisualTileCoordinates(picBox)[0];

                            //If the user is visualising the entirety of the map and adds a tile, the tile is put on top of the highest component.
                            if (inTopView)
                            {
                                map.ChangeTile(x, y, GetHighestAvailableLayer(x, y), selectedType);
                            }
                            else
                            {
                                map.ChangeTile(x, y, view.cmbLayer.SelectedIndex, selectedType);
                            }
                        }
                        picBox.Focus();
                        SelectPictureBox(picBox);
                    }
                }
                else
                {
                    if (!inTopView)
                    {
                        //Save the sender's coordinates.
                        int destinationX = GetTileAssociatedWithPictureBox(picBox).PosX;
                        int destinationY = GetTileAssociatedWithPictureBox(picBox).PosY;

                        //Remove the dragged tile from its original position.
                        map.ChangeTile(tileBeingDragged.PosX, tileBeingDragged.PosY, view.cmbLayer.SelectedIndex, TileFactory.TileType.emptyTile);

                        //Set the tile being dragged's coordinates to the destination
                        tileBeingDragged.PosX = destinationX;
                        tileBeingDragged.PosY = destinationY;

                        //Change the sender's tile to the time being dragged.
                        map.LayerList[view.cmbLayer.SelectedIndex].Tiles[map.Height * GetVisualTileCoordinates(picBox)[0] + GetVisualTileCoordinates(picBox)[1]] = tileBeingDragged;

                        tileBeingDragged = null;
                        tileBeingDraggedPictureBox = null;
                        SelectPictureBox(picBox);
                        view.RefreshView();
                    }
                }
            }
 /// <summary>
 /// Selects the tile.
 /// </summary>
 /// <param name="picBox">The pic box.</param>
 private void SelectPictureBox(PictureBox picBox)
 {
     selectedTile = GetTileAssociatedWithPictureBox(picBox);
     view.propGrid.SelectedObject = GetTileAssociatedWithPictureBox(picBox);
     picBox.BorderStyle = BorderStyle.Fixed3D;
     view.statusStripTileX.Text = selectedTile.PosX.ToString();
     view.stripStatusTileY.Text = selectedTile.PosY.ToString();
 }
            /// <summary>
            /// Deactivates the tiles.
            /// </summary>
            /// <param name="form">The form.</param>
            private void DeactivateTiles(Control form)
            {
                foreach (Control cControl in form.Controls)
                {
                    if (cControl is PictureBox)
                    {
                        if (selectedTile != null)
                        {
                            if (!IsSelectedTile((PictureBox)cControl) && ((PictureBox)cControl).BorderStyle == BorderStyle.Fixed3D)
                            {
                                if (activeTile != null && !IsActiveTile((PictureBox)cControl))
                                {
                                    activeTile = null;
                                    ((PictureBox)cControl).BorderStyle = BorderStyle.FixedSingle;
                                }
                            }
                        }
                        else
                        {
                            if (activeTile != null && !IsActiveTile((PictureBox)cControl))
                            {
                                activeTile = null;
                                ((PictureBox)cControl).BorderStyle = BorderStyle.FixedSingle;
                            }
                        }
                    }

                }
            }
 /// <summary>
 /// Handles the OnLeave event of the Tile control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 public void Tile_OnLeave(object sender, EventArgs e)
 {
     PictureBox picBox = (PictureBox)(sender);
     if (!IsSelectedTile(picBox))
     {
         picBox.BorderStyle = BorderStyle.FixedSingle;
         activeTile = null;
     }
 }
            /// <summary>
            /// Handles the OnHover event of the Tile control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
            public void Tile_OnHover(object sender, EventArgs e)
            {
                PictureBox picBox = (PictureBox)(sender);
                //If another tile is already active, deactivate it.
                if (activeTile != null)
                {
                    DeactivateTiles(view.paEditor);
                }

                //If no tile is selected,
                picBox.BorderStyle = BorderStyle.Fixed3D;
                activeTile = GetTileAssociatedWithPictureBox(picBox);

                if (selectedTile == null)
                {
                    view.statusStripTileX.Text = activeTile.PosX.ToString();
                    view.stripStatusTileY.Text = activeTile.PosY.ToString();
                }
            }