Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在Visual Basic中跳过循环中的迭代_Vb.net_Loops - Fatal编程技术网

Vb.net 在Visual Basic中跳过循环中的迭代

Vb.net 在Visual Basic中跳过循环中的迭代,vb.net,loops,Vb.net,Loops,我试图让这个循环跳过20个像素,然后画下一个方框。我按照我的编码方式完美地并排画出了这些盒子。但我不知道如何让它跳过像素。我认为这是一个简单的添加,但我看不到它。我也在谷歌上搜索了其他的循环,但我无法找出我遗漏了什么,我也读了几本书。 以下是我所拥有的: Public Class Form1 Const CellWidth As Integer = 50 Const cellHeight As Integer = 50 Const xOffset As Integer

我试图让这个循环跳过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

看起来每次迭代都要从x值中减去20个像素。你的意思是加20吗?另外,在设置location.X和Y时,您可能想说(col*CellWidth)+1。感谢您的响应,我将尝试这些更改,偏移量只是移动for循环的开始绘制区域,但您已经将其移动了单元格的宽度+1(使用我的第二个更改),然后减去20。不知道你为什么这么做。如果你想在每个图像之间有一个20像素的缓冲区,你需要加20。