Search code examples
c#winformsgraphic

Creating a map larger than form in C#


I'm trying to create some sort of simulation program and I've searched the net for answers but couldn't find a fitting one.

My program will have like 10000 x 10000 map with X and Y coordinates and I'd like to find a way to have this large "map" but only displaying a selected part of this map on a form / panel. (You can move on the map with eihter buttons placed or keys doesn't really matter I know how to do that part)

I'm looking to find a way to create and display this large map without using XNA, DirectX or any other advaced graphical engine, just like the simple system.graphic and / or system.graphic2d

Thank you for your help!


Solution

  • Place a panel on your form, sized to the appropriate dimension. Then place a picturebox in the panel, sized to the dimensions of your map graphic (in other words, the picturebox is now larger than its container control, the panel). Set the Picturebox.Sizemode to "Normal."

    Set the Autoscroll property of the panel to "True."

    Load the map. Scrollbars will ba available to navigate the map image, and you could also set up some buttons or other navigation.

    You can do all of the above within the VS designer, or programmatically with code.

    It's basic, but it will get the job done (or, started, anyway!) Hope that helps.