在VB框架区域内单击鼠标,会在文本框中显示出左右键的单击次数和总的单击次数。命令如何编写

来源:百度知道 编辑:UC知道 时间:2024/06/18 09:48:10

在窗体上放一个框架控件,3个标签控件,3个文本框控件,每个标签对应一个文本框,那么代码如下了
Private Sub Form_Load()
Frame1.Caption = "鼠标单击测试区域"
Label1.Caption = "左键单击次数"
Label2.Caption = "右键单击次数"
Label3.Caption = "单击鼠标次数"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub

Private Sub Frame1_Click()
Static n As Integer
n = n + 1
Text3.Text = n
End Sub

Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1
Static a As Integer
a = a + 1
Text1.Text = a
Case 2
Static b As Integer
b = b + 1
Text2.Text = b
End Select
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Text1.Text = Val(Text1.Text) + 1
ElseIf Button = 2 Then
Text2.Text = Val(Tex