
07-22-2012, 09:43 PM
|
|
Junior Contributor
|
|
Join Date: Mar 2006
Posts: 372
|
|
Trouble dividing a rectangle into equal parts
|
I am drawing graphics on a print preview dialog. I am making a square around the page at the margins. I then want to draw 20 horizontal rectangles within this large rectangle. Seems simple, right?
Well, I notice something odd...This code works if I do a few rectangles. But, when I try more, the spacing never works out. I dont know what is happening. Any ideas?
Code:
'draw large rectangle
Dim Pen1 As New Pen(Brushes.Black)
Dim rWidth, rHeight As Integer
rWidth = e.MarginBounds.Right - e.MarginBounds.Left
rHeight = e.MarginBounds.Bottom - e.MarginBounds.Top
Dim r1 As New Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, rWidth, rHeight)
e.Graphics.DrawRectangle(Pen1, r1)
'set 0,0 at margin bounds
Dim Datum As Point = New Point(e.MarginBounds.Left, e.MarginBounds.Top)
'get the size of 1/20 the rectangle from above
Dim Bar As Size = New Size((rWidth / 20), rHeight)
'draw a rec, starting at 0, count up tp 20.
'each time increase x by bar width
For BarCount As Integer = 0 To 19
e.Graphics.DrawRectangle(Pens.Blue, Datum.X, Datum.Y, Bar.Width, Bar.Height)
Datum.X = Datum.X + Bar.Width
Next
e.HasMorePages = False
|
Last edited by bonedoc; 07-22-2012 at 10:16 PM.
|