Visual Studio-使用计时器控件打印数组元素

时间:2019-03-16 00:13:51

标签: visual-studio visual-studio-2015

我正在创建一个程序,使用计时器控件一次打印一个数组元素(从左上到右下),但是,它不是一次打印一个元素,而是一次打印所有元素。同时。我需要帮助,下面是示例屏幕截图和到目前为止的代码。

enter image description here

Public Class SymbolDrawFRM
Private symbol(10, 10) As String

Sub Drawing()
    Dim s As String = ""
    For i = 1 To rowNUD.Value
        For j = 1 To columnNUD.Value
            s = s & symbol(i, j) & # & " "
        Next
        s = s & vbCrLf
    Next
    outputTBX.Text = s
End Sub

Private Sub startStopBTN_Click(sender As Object, e As EventArgs) Handles startStopBTN.Click
    Timer.Start()
End Sub

Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
    Drawing()
End Sub
End Class

1 个答案:

答案 0 :(得分:1)

忽略数组,仅使用NumericUpDown控件:

Private Sub startStop_Click(sender As Object, e As EventArgs) Handles startStop.Click
    Timer1.Interval = 500
    Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Static x As Integer
    Static y As Integer
    If x = 0 And y = 0 Then
        outputTBX.Clear()
    End If

    outputTBX.AppendText("# ")
    x = x + 1
    If x = columnNUD.Value Then
        x = 0
        outputTBX.AppendText(vbCrLf)
        y = y + 1
        If y = rowNUD.Value Then
            x = 0
            y = 0
            Timer1.Stop()
            MessageBox.Show("Done!")
        End If
    End If
End Sub