我试图让这个循环跳过20像素然后绘制下一个框。我完全按照我编码的方式并排绘制盒子。但我无法弄清楚如何让它跳过像素。我认为这是一个简单的补充,但我看不到它。我也搜索了其他的循环,但我无法找出我所缺少的东西,而且我也读了几本书。 这就是我所拥有的:
Public Class Form1
Const CellWidth As Integer = 50
Const cellHeight As Integer = 50
Const xOffset As Integer = -20
Const yOffset As Integer = 25
Private DEFAULT_BACKCOLOR As Color = Color.White
Public Sub DrawBoard()
Dim location As New Point
'---draws the boxes
For row As Integer = 1 To 9
For col As Integer = 1 To 9
location.X = col * (CellWidth + 1) + xOffset
location.Y = row * (cellHeight + 1) + yOffset
Dim lbl As New Label
With lbl
.Name = col.ToString() & row.ToString()
.BorderStyle = BorderStyle.Fixed3D
.Location = location
.Width = CellWidth
.Height = cellHeight
.TextAlign = ContentAlignment.MiddleCenter
.BackColor = DEFAULT_BACKCOLOR
.Font = New Font(.Font, .Font.Style Or FontStyle.Bold)
.Tag = "1"
End With
Me.Controls.Add(lbl)
Next
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DrawBoard()
End Sub
End Class