views:

21

answers:

1

I want to draw a table in my print output using the System.Drawing.Printing's Graphics object. I'm trying to use the DrawRectangle to draw my table cells. This requires drawing several rectangles in a row. It should be pretty easy, right? Well it appears that DrawRectangle four parameters are x, y, width, and height. However x and y are integers while width and height are singles. My rectangles are overlapping because the next cell in a row cannot base its x position on the width of the previous rectangle. In other words, the x position and width are different data types and don't use the same scale. How can I calculate the x position of the next cell based on the width of the previous cell?

A: 

I don't see any overloads for DrawRectangle that contain different data types:

http://msdn.microsoft.com/en-us/library/fxtkbx2d.aspx

Different widths should not matter, you simply add the width of the current rectangle to X and draw the next rectangle at that position. (If your rectangles are in different units then you need to provide more information in your post. Someone may be able to help you convert between units.)

Some psuedocode:

current = new Rectangle(0, 0, 100, 50)
while (current.x + current.width) < page_width
  DrawRectangle(Pens.Black, current.x, current.y, current.width, current.height)
  current.x += current.width
  current.width = width_of_next_rectangle
end while
Pineapple