Option Explicit
Dim total As Integer, current As Integer
Private Sub cmd2_Click(Index As Integer)
If Index = 0 Then current = 0
If Index = 1 Then current = current - 1
If Index = 2 Then current = current + 1
If Index = 3 Then current = total
If current = 0 Then
Call Ena_Button(cmd2(0), cmd2(1), cmd2(2), cmd2(3), 0, 0, 1, 1)
ElseIf current = total Then
Call Ena_Button(cmd2(0), cmd2(1), cmd2(2), cmd2(3), 1, 1, 0, 0)
Else
Call Ena_Button(cmd2(0), cmd2(1), cmd2(2), cmd2(3), 1, 1, 1, 1)
End If
End Sub
Private Sub Cmd1_Click(Index As Integer) '不对中间按钮设置 Enable
If Index = 0 Then '添加时
Call Ena_Button(Cmd1(0), Cmd1(1), Cmd1(3), Cmd1(4), 0, 0, 1, 1)
End If
If Index = 1 Then '修改时
Call Ena_Button(Cmd1(0), Cmd1(1), Cmd1(3), Cmd1(4), 0, 0, 1, 1)
End If
If Index = 2 Then '删除时
Index = 3
End If
If Index = 4 Then
Index = 3
End If
If Index = 3 Then '取消时
Call Ena_Button(Cmd1(0), Cmd1(1), Cmd1(3), Cmd1(4), 1, 1, 0, 0)
End If
End Sub
Private Sub Form_Load()
total = 6
current = 0
cmd2_Click (0) '初始按钮状态
Cmd1_Click (3) '初始按钮状态
End Sub
Public Sub Ena_Button(C1 As CommandButton, C2 As CommandButton, C3 As CommandButton, C4 As CommandButton, n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer)
'''用按钮控制数据记录移动时,改变按钮的可用状态
'''设置按钮是否可用.
'''C1,参与进来的按钮
'''n1,对应标识
'''
'''
C1.Enabled = n1
C2.Enabled = n2
C3.Enabled = n3
C4.Enabled = n4
End Sub
VB,多按钮的相互操作处理
最新推荐文章于 2023-05-31 00:18:11 发布