如何为多个PictureBox一次单击处理多个事件?

时间:2017-04-22 05:37:02

标签: vb.net

所以我想要做的是做一个测验,你选择答案的正确的图片,必须点击。我需要5个问题,但是通过使用Select Case方法,你无法直接投射Picturebox1.click

Question with multiple picture answers which after you click will pop messagebox.show function and move on to the next question 任何帮助将不胜感激!!

(
emp_no  dept_name   from_date   to_date
)

3 个答案:

答案 0 :(得分:0)

Private Sub control1_mouseclick1(sender As Object, e As EventArgs) Handles PictureBox2.Click, PictureBox3.Click, PictureBox1.Click, PictureBox4.Click

    Select Case e
        Case 1
            If (PictureBox2.Click = True) Then
                MessageBox.Show("CORRECT!")
            Else
                MessageBox.Show("INCORRECT!")

            End If
            quest2()


    End Select
End Sub

你是对的,它可能没有意义..我想要做的是在代码中完全显示,但PictureBox2.Click不能直接在这里执行,而我作为初学者不知道如何正确的我可以做到..以前的代码我试图使用在论坛上找到的其他人的建议,但我不清楚如何正确使用它,所以我甚至没有打扰自己。希望你知道!

答案 1 :(得分:0)

如果您想知道点击了哪个PictureBox,您可以执行以下操作:

Private Sub control1_mouseclick1(sender As Object, e As EventArgs) Handles PictureBox2.Click, PictureBox3.Click, PictureBox1.Click, PictureBox4.Click
    Dim pb As PictureBox = DirectCast(sender, PictureBox)

    If pb Is PictureBox1 Then

    ElseIf pb Is PictureBox2 Then

    ElseIf pb Is PictureBox3 Then

    ElseIf pb Is PictureBox4 Then

    End If
End Sub

答案 2 :(得分:0)

那对我有意义,谢谢。但另一个问题发生..         Private Sub control1_mouseclick1(sender As Object,e As EventArgs)处理PictureBox2.Click,PictureBox3.Click,PictureBox1.Click,PictureBox4.Click Dim pb As PictureBox = DirectCast(sender,PictureBox)

    Select Case e
        Case 1
            If pb Is PictureBox2 Then
                MessageBox.Show("Correct!")
                Form1.scorepoint += 1
            ElseIf pb Is PictureBox1 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox3 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox4 Then
                MessageBox.Show("Incorrect!")
            End If
            question2()
        Case 2
            If pb Is PictureBox1 Then
                MessageBox.Show("Correct!")
                Form1.scorepoint += 1
            ElseIf pb Is PictureBox2 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox3 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox4 Then
                MessageBox.Show("Incorrect!")
            End If
            question3()
        Case 3
            If pb Is PictureBox4 Then
                MessageBox.Show("Correct!")
                Form1.scorepoint += 1
            ElseIf pb Is PictureBox1 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox3 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox2 Then
                MessageBox.Show("Incorrect!")
            End If
            question2()
        Case 4
            If pb Is PictureBox3 Then
                MessageBox.Show("Correct!")
                Form1.scorepoint += 1
            ElseIf pb Is PictureBox1 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox2 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox4 Then
                MessageBox.Show("Incorrect!")
            End If
            question5()
        Case 5
            If pb Is PictureBox3 Then
                MessageBox.Show("Correct!")
                Form1.scorepoint += 1
            ElseIf pb Is PictureBox1 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox2 Then
                MessageBox.Show("Incorrect!")
            ElseIf pb Is PictureBox4 Then
                MessageBox.Show("Incorrect!")
            End If
    End Select
    Form1.trackscore()
End Sub

所以,当我调用select case方法时,每个Case" number"未声明,它显示错误"运营商' ='没有为System.EventArgs类型定义。'和'整数' 在顶部,我有 ' Dim e As Integer'这是我的Select Case变量''