发布网友 发布时间:2023-05-16 07:12
共1个回答
热心网友 时间:2024-11-25 16:37
Dim i As Integer '动态显示的元素的下标值
Sub Form_Load() '加载时计算元素并确定位置
Dim H%, L%, S% '行号、列号、数
Dim A(15, 15) As Integer
Pic.Move 0, 0, (Cmd(0).Width + 5) * N + 20, (Cmd(0).Height + 5) * N + 20
Form2.Width = Pic.Width + 50
Form2.Height = Pic.Height + 900
Cmd1.Top = Pic.Height + 100
Cmd2.Top = Cmd1.Top
Cmd1.Left = Form2.Width / 4 - Cmd1.Width / 2
Cmd2.Left = Form2.Width * 3 / 4 - Cmd1.Width / 2
Cmd(0).Visible = False
S = 1: H = 1: L = (N + 1) / 2 '第1个数
A(H, L) = S
Load Cmd(1)
Cmd(1).Visible = True
Cmd(1).Left = 5 + (L - 1) * Cmd(0).Width
Cmd(1).Top = 5 + (H - 1) * Cmd(0).Height
For S = 2 To N * N '计算2以后的元素的放入位置
H = H - 1
L = L + 1
If H < 1 And L > N Then H = 2: L = N
If H < 1 Then H = N '行号越界
If L > N Then L = 1 '列号越界
If A(H, L) <> 0 Then H = H + 2: L = L - 1 '已有元素
A(H, L) = S
Load Cmd(S) '回载相应的按钮元素
Cmd(S).Visible = True
Cmd(S).Left = 5 + (L - 1) * Cmd(0).Width
Cmd(S).Top = 5 + (H - 1) * Cmd(0).Height
Next S
S = 0
For H = 1 To N '计算第1列的和
S = S + A(1, H)
Next H
Form2.Caption = N & "阶:各项和均等于" & S
i = 0
Timer1.Enabled = True
Timer1.Interval = T
End Sub
Sub Timer1_Timer() '呈现数值并变换颜色
i = i + 1
If i > N * N Then
Timer1.Enabled = False
Cmd(N * N).BackColor = QBColor(11)
Else
Cmd(i).Caption = i
Cmd(i).BackColor = QBColor(12)
Cmd(i - 1).BackColor = QBColor(11)
End If
End Sub
Sub Cmd1_Click()
Unload Form2
Form1.Show
End Sub
Sub Cmd2_Click()
End
End Sub