累加计算器

版权声明: https://blog.csdn.net/eds124/article/details/82795613
Public Class Form1
    Dim tblist As TextBox() = New TextBox(49) {}
    Dim l As Label = New Label()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Location = New Point(0, 0)
        Me.Size = New Size(800, 1050)

        l.Text = "结果"
        l.Location = New Point(200, 200)
        l.Size = New Size(500, 50)
        l.Font = New Font("微软雅黑", 20)
        Me.Controls.Add(l)

        For i As Integer = 0 To tblist.GetLength(0) - 1
            tblist(i) = New TextBox()
            tblist(i).Location = New Point(0, i * 20)
            tblist(i).MaxLength = 20
            Me.Controls.Add(tblist(i))
            AddHandler tblist(i).TextChanged, New EventHandler(AddressOf Me.tblist_textchanged)
        Next

        tblist(0).TabIndex = 0
        
    End Sub

    Private Sub tblist_textchanged(ByVal o As Object, ByVal ea As EventArgs)
        Dim d As Double = 0

        For i As Integer = 0 To tblist.GetLength(0) - 1
            d += Val(tblist(i).Text)
        Next
        l.Text = d
    End Sub
End Class

猜你喜欢

转载自blog.csdn.net/eds124/article/details/82795613
今日推荐