I'm supposed to create a magic square in 2D using Windows Forms Application. It should look like this:
However, the user should be able to decide the size of the square (3x3, 5x5, 7x7, etc). I already wrote the code in a Console Application, but I don't know how to add the 2D graphics.
Somebody already asked this question (How do I put my result into a GUI?), and one of the answers was to use DataGridView
, but I'm not sure if that's what I'm looking for, since I can't make it look like the picture.
Any ideas or advice?
You can create a Form and add a TableLayoutPanel with this property
and this is the result
When you create Row and Column, to fit correctly set the percentage in this way:
After this you can add a Button or Label in each square.
You can use a
TableLayoutPanel
and add buttons to panel dynamically.If you don't need interaction with buttons, you can add
Label
instead.Create square dynamically:
If you need interaction with buttons
As an example, you can call
Screenshot: