CRIAR GRADE AUTOMATIZAR PROCESSO

FROSTYNHO 01/06/2011 10:20:07
#375545
estou usando o seguinte codigo pra criar uma grade numa picturebox:

Public SlicePen As Pen
Public SlicePenSize As Integer = 1
Public SlicePenDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Public SlicePenColor As Color = Color.Yellow

Dim iWidth As Integer = 16
Dim iHeight As Integer = 16

SlicePen = New Pen(SlicePenColor, SlicePenSize)
SlicePen.DashStyle = DashStyle.Solid

PictureBox1.Refresh()

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, 0, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, 0, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight * 2, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight * 2, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight * 3, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight * 3, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight * 4, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight * 4, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight * 5, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight * 5, iWidth, iHeight)

PictureBox1.CreateGraphics.DrawRectangle(SlicePen, 0, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 2, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 3, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 4, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 5, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 6, iHeight * 6, iWidth, iHeight)
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * 7, iHeight * 6, iWidth, iHeight)


porém queria automatizar esse codigo, pra ir adicionando a grade sem ter que ir repetindo o codigo assim, alguem tem ideia de como posso fazer isso?
KERPLUNK 01/06/2011 10:28:45
#375549
Resposta escolhida
Algo bem parecido com isso:
for i = 0 to 6
for j = 0 to 7
PictureBox1.CreateGraphics.DrawRectangle(SlicePen, iWidth * i, iHeight * j, iWidth, iHeight)
next j
next i
Tópico encerrado , respostas não são mais permitidas