怎样在vb中按钮下去添加按钮指示灯
PrivateSubCommand5_Click()Dimj()AsByteDimj_TxtAsStringDimiAsIntegerj_Txt=Text3IfLen(T...
Private Sub Command5_Click()
Dim j() As Byte
Dim j_Txt As String
Dim i As Integer
j_Txt = Text3
If Len(Text3) Mod 2 = 0 And Len(Text3) <> 0 Then '检验16进制字符串长
ReDim j(Len(j_Txt) / 2 - 1)
For i = 0 To Len(j_Txt) - 1 Step 2
j(i / 2) = Val("&H" & Mid(j_Txt, i + 1, 2))
Next
If MSComm1.PortOpen = True Then
MSComm1.Output = j
Else
MSComm1.PortOpen = True
Shape2.FillColor = vbGreen
MSComm1.Output = j
End If
Else
MsgBox ("格式不对!")
End If
End Sub
我按下按钮怎么shape还是红色而不是绿色,要怎么改! 展开
Dim j() As Byte
Dim j_Txt As String
Dim i As Integer
j_Txt = Text3
If Len(Text3) Mod 2 = 0 And Len(Text3) <> 0 Then '检验16进制字符串长
ReDim j(Len(j_Txt) / 2 - 1)
For i = 0 To Len(j_Txt) - 1 Step 2
j(i / 2) = Val("&H" & Mid(j_Txt, i + 1, 2))
Next
If MSComm1.PortOpen = True Then
MSComm1.Output = j
Else
MSComm1.PortOpen = True
Shape2.FillColor = vbGreen
MSComm1.Output = j
End If
Else
MsgBox ("格式不对!")
End If
End Sub
我按下按钮怎么shape还是红色而不是绿色,要怎么改! 展开
1个回答
展开全部
你这个指示灯是要常亮的(就是按了Command5后它就固定变为绿色,除非再次改变)还是随按钮的动作变色的(按下去是绿色,弹起来后是红色)?如果是常亮的,那么你应该把Shape2.FillColor = vbGreen这一句移到它下下一行的End If的下一行。如果是后者,那么就要改用MouseDown和MouseUp事件来控制shape的颜色:
Private Sub Command5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape2.FillColor = vbGreen
End Sub
Private Sub Command5_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape2.FillColor = vbRed
End Sub
Private Sub Command5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape2.FillColor = vbGreen
End Sub
Private Sub Command5_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape2.FillColor = vbRed
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询