I'm not familiar with the examples you reference, but I have been designing a tile-based grid which your post has convinced me to develop into a user control.
The basic idea is a grid of squares that can be clicked on or accessed progamatically by tile. here's the basic logic behind it:
Define a Tile size in pixels (say 32x32) Define a Grid Size in tiles (say 64x64) Define a View Size in tiles (say 9x9) Define a CurrentPosition as a Tile Index
Create an Array of TilesObjects (min props of Index, PositionX - in tiles, PositionY - in tiles) Create an Array of Rectanges for each in ViewSize
Size a PictureBox to ViewSize * TileSize
Have the Paint Event for the picture box draw TileSize rectangles for each tile in ViewSize
In the click event for picture box, enumerate through the Rectange Array and see if a 1 pixel rectange at mouse.position intersects the current rectange. when it does, you found the one that the user clicked. now you can calculate which tile that is in the underlying TileObject array by working off of current position and the location of the intersecting rectangle.
I'm going to put this into a user control with a picture box and some scroll bars. If you want to brainstorm this some more, just post! |