1

I currently have a complete game of life program written where nearly everything is done in classes. I'm trying to figure out how to display my 2D array (which is my Game of Life grid) in a windows form picturebox, as currently I only know how to run it in the console.

I'm very new to windows forms so as detailed of help as possible would be great :)

I have a class called Cell which represents each cell in the grid, and a class called GOL which represents a grid. Gol contains methods for setting the live cells and for updating each iteration of the grid in the game.

I know that I need to create a bitmap out of the 2D array, and somehow also use my methods on it, and then display that in the picturebox. No idea how to do any of it.

Thanks :)

Orion Hall
  • 77
  • 1
  • 5
  • You can create a `TableLayoutPanel` and [draw cells with back colors](http://stackoverflow.com/questions/34064499/how-to-set-cell-color-in-tablelayoutpanel-dynamically) based on your input array. Also you can [dynamically add some controls](http://stackoverflow.com/questions/34426888/dynamic-button-creation-placing-them-in-a-predefined-order-using-c-sharp) like panel to `TableLayoutPanel` having backcolor based on your input array. – Reza Aghaei Oct 15 '16 at 03:00
  • I'll try that.. once I wrap my mind around where that code would go, how to pass my input array into it, how to make the picturebox display it, etc.. but thank you for pointing me in a direction! – Orion Hall Oct 15 '16 at 03:24
  • My answer doesn't use `PictureBox`. It relies on `TableLayoutPanel` instead. Take a look at linked posts. For example in [this post](http://stackoverflow.com/a/34088085/3110834) I used an array of colors to colorize `TableLayoutPanel` cells. – Reza Aghaei Oct 15 '16 at 04:45

1 Answers1

0

The example for System.Drawing.Bitmap shows setting some pixels and displaying it with a PictureBox. Instead of creating a Bitmap from file you can just create one the same size as your grid new Bitmap(width, height)

gordy
  • 9,360
  • 1
  • 31
  • 43