Picturebox click event handling. (Resolved)
I want to have each click on the picturebox do something according to which click it is. The first will set the box to 3d border, the next will set it back to no border.
I thought for sure this would work:
VB Code:
Private Sub pbxDieOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbxDieOne.Click
If clickCntrD1 = 0 Then
clickCntrD1 += 1
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
'next the image will become a blank die so we can tell which dice we have chosen to change
End If
If clickCntrD1 = 1 Then
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
'next the image will become a blank die so we can tell which dice we have chosen to change
clickCntrD1 = 0
End If
But alas, the picturebox's border doesn' change. The picturebox's border will change if I have only one action for it to take, like just make the picturebox's border 3d when someone clicks on it. But I want the person to be able to click on the picturebox again to reset it.
THank you in advance.
Re: Picturebox click event handling.
The best way to handle this is based on the current border style...
VB Code:
Select Case pbxDieOne.BorderStyle
Case BorderStyle.None
pbxDieOne.BorderStyle = BorderStyle.FixedSingle 'If you dont want fixed single comment-out this line
Case BorderStyle.FixedSingle ' And this line
pbxDieOne.BorderStyle = BorderStyle.Fixed3D
Case BorderStyle.Fixed3D
pbxDieOne.BorderStyle = BorderStyle.None
End Select
Re: Picturebox click event handling.
That is an excellent idea. I will give that a go.
I am curious tho, why won't the way I tried it work?
Re: Picturebox click event handling.
VB Code:
If clickCntrD1 = 0 Then
[b]clickCntrD1 += 1[/b]
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
'next the image will become a blank die so we can tell which dice we have chosen to change
End If
[b]If clickCntrD1 = 1 Then[/b]
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
'next the image will become a blank die so we can tell which dice we have chosen to change
clickCntrD1 = 0
End If
Your way is underminding it self... if you look at the bolded areas you will notice that you set the value to 1 then the next bolded statement is true so then it sets the border style back.
Re: Picturebox click event handling.
I fixed your code here:
VB Code:
If clickCntrD1 = 0 Then
clickCntrD1 += 1
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
'next the image will become a blank die so we can tell which dice we have chosen to change
Else
pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
'next the image will become a blank die so we can tell which dice we have chosen to change
clickCntrD1 = 0
End If
Re: Picturebox click event handling.
Ahhh, yes I see now what I did. It's not going to run one if and then exit the procedure, it will go to the next if right afterwards.
Yes now I see why it should work. I need else if.
Thanks for letting me see how that works better. I understand so much better now.
Cheers