![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Location: Ireland
Posts: 5
Rep Power: 0
![]() |
Am able to draw first line of eight squares but cannot create next rows:
Here is the code that im using. Private Rects() As Rectangle Protected Overrides Sub OnLoad(ByVal e As EventArgs) MyBase.OnLoad(e) Dim w As Integer = Me.pbMain.Width Dim h As Integer = Me.pbMain.Height Dim numVlines As Integer = CInt(w / 8) Dim numHLines As Integer = CInt(h / 8) Dim b As New Bitmap(w, h) Dim ppi As Single = w / 8 Dim startX As Integer = 0 Dim clr As Color = Color.Black Dim switchClr As Boolean = False Dim g As Graphics = Graphics.FromImage(b) g.Clear(Color.White) For i As Integer = 1 To numVlines If switchClr Then clr = Color.Green switchClr = False Else clr = Color.GreenYellow switchClr = True End If Dim rect As New Rectangle(startX, 0, ppi, ppi) g.FillRectangle(New SolidBrush(clr), rect) g.DrawRectangle(New Pen(Color.White), rect) ReDim Preserve Rects(i) Rects(i) = rect startX += rect.Width Next Me.pbMain.Image = b |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Perhaps this will work better
Dim w As Integer = Me.pbMain.Width Dim h As Integer = Me.pbMain.Height Dim SizeX as integer = w / 8 Dim SizeY as integer = w / 8 Const columns As Integer = 8 Const rows As Integer = 8 Dim b As New Bitmap(w, h) Dim g As Graphics = Graphics.FromImage(b) Dim clr As Color = Color.Black Dim switchClr As Boolean = False dim rects(row - 1, columns - 1) as rectangle g.Clear(Color.White) For i As Integer = 1 To rows For j as integer = 1 to columns If switchClr Then clr = Color.Green switchClr = False Else clr = Color.GreenYellow switchClr = True End If Dim rect As New Rectangle(i * sizex, j * sizey, sizex, sizey) g.FillRectangle(New SolidBrush(clr), rect) g.DrawRectangle(New Pen(Color.White), rect) rects(i,j) = rect Next next Me.pbMain.Image = b 8x8 grid that scales to the picture box. It was supposed to be 8x8, right? Or did you want the number of rectangles to depend on the size of the box? |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 22
Rep Power: 0
![]() |
I'd say this works better
Dim i, j As Integer
Dim w As Integer = Me.pbmain.Width
Dim h As Integer = Me.pbmain.Height
Dim SizeX As Integer = w / 8
Dim SizeY As Integer = h / 8
Const columns As Integer = 8
Const rows As Integer = 8
Dim b As New Bitmap(w, h)
Dim g As Graphics = Graphics.FromImage(b)
Dim clr As Color = Color.Black
Dim switchClr As Boolean = False
g.Clear(Color.White)
For i = 0 To rows - 1
switchClr = Not switchClr
For j = 0 To columns - 1
If switchClr Then
clr = Color.Green
switchClr = False
Else
clr = Color.GreenYellow
switchClr = True
End If
Dim rect As New Rectangle(i * SizeX, j * SizeY, SizeX, SizeY)
g.FillRectangle(New SolidBrush(clr), rect)
g.DrawRectangle(New Pen(Color.Black), rect)
Next
Next
Me.pbmain.Image = b |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|