Question Draw the squares on exam paper


New member
Apr 15, 2013
Programming Experience
Good day to all.

I have little experience with C#, and my boss asked me to make a program that will get some serial number from a DB, and print it as squares, in the right position, in a paper. Much like this image (
Well, I can get the numbers, but I have no idea of how to make such print. Does anyone have a idea of what I?m talking about, and can point me to the right direction of what I need to study?


Edit: I need only to draw the squares in black... the paper, with the rest of the text, and the locations of the squares, are already printed.
.NET printing is based around the PrintDocument class. In the most basic case, you create a PrintDocument (which you can add to a form in the designer), call its Print method and then handle its PrintPage event. In the PrintPage event handler, you use the Graphics object provided to draw your printed output using GDI+, just as you would draw on a control in its Paint event handler. In your case, you'd want to call the FillRectangle method of the Graphics object.

I would suggest that you start by doing a bit of reading on GDI+, the Graphics class and its FillRectangle method. You can test by simply drawing on a form. Once you're comfortable with that part, do some reading on .NET printing, the PrintDocument class and its PrintPage event. You can then basically transfer your existing GDI+ code into the PrintPage event handler of the PrintDocument.

Latest posts

Top Bottom