I would like to draw a table using System.Drawings, and then fill cells with some text. This text will change every few seconds, in various moments of time. It's a game, where there is a grid and every few seconds, random cell displays a number for a split of a second, then the user has to type the answer in the text box below it. Also, user has to click the cell, which has just showed the number. I have little experience in working with Graphics in window so any help will be greatly appreciated.
Asked
Active
Viewed 4,029 times
3
-
Does it have to be winforms or can it be WPF? – Conrad Frix May 31 '11 at 14:52
-
Here is one related post, http://stackoverflow.com/questions/5461338/how-to-create-a-jpg-image-dynamically-in-memory-with-net/ – Karthik Mahalingam May 31 '11 at 14:57
-
The link from @Karthik is of great help! Thank you! – Macin Jun 01 '11 at 07:35
1 Answers
2
Have you considered using the DataGridView Control instead?
If you prefer to use a more low-level approach, drawing a table is not that hard. Subdivide the x
and y
coordinates to obtain points for drawing (System.Drawing.Point
)
Draw lines using a pen (System.Drawing.Pen
) and two points as arguments to Graphics.DrawLine
method. You can position your numbers at midpoint of cells because you already know all of the points (and their coordinates) used to draw table lines.
You can determine which cell was clicked also by coordinates.

ipavlic
- 4,906
- 10
- 40
- 77
-
this has to be done using System.Drawing as part of the project requirements. – Macin May 31 '11 at 14:23
-
Would this be efficient solution then: Store coordinates of each cell (i.e. top left corner) in a dictionary, and then look up cell index whenever user clicks on a cell? I've never done much low level graphic programming, therefore my simple questions. Greatly appreciate your help! – Macin Jun 01 '11 at 07:37
-
However, it might be difficult to find dictionary key based on value. What is the other most common solution to this? – Macin Jun 01 '11 at 07:49