Results 1 to 6 of 6

Thread: Picturebox click event handling. (Resolved)

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved 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:
    1. Private Sub pbxDieOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbxDieOne.Click
    2.         If clickCntrD1 = 0 Then
    3.             clickCntrD1 += 1
    4.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
    5.             'next the image will become a blank die so we can tell which dice we have chosen to change
    6.         End If
    7.         If clickCntrD1 = 1 Then
    8.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
    9.             'next the image will become a blank die so we can tell which dice we have chosen to change
    10.             clickCntrD1 = 0
    11.         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.
    Last edited by gjon; Feb 2nd, 2005 at 12:00 AM.

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Picturebox click event handling.

    The best way to handle this is based on the current border style...

    VB Code:
    1. Select Case pbxDieOne.BorderStyle
    2.             Case BorderStyle.None
    3.                 pbxDieOne.BorderStyle = BorderStyle.FixedSingle 'If you dont want fixed single comment-out this line
    4.             Case BorderStyle.FixedSingle ' And this line
    5.                 pbxDieOne.BorderStyle = BorderStyle.Fixed3D
    6.             Case BorderStyle.Fixed3D
    7.                 pbxDieOne.BorderStyle = BorderStyle.None
    8.         End Select
    Last edited by <ABX; Feb 1st, 2005 at 11:52 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    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?

  4. #4
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Picturebox click event handling.

    VB Code:
    1. If clickCntrD1 = 0 Then
    2.             [b]clickCntrD1 += 1[/b]
    3.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
    4.             'next the image will become a blank die so we can tell which dice we have chosen to change
    5.         End If
    6.         [b]If clickCntrD1 = 1 Then[/b]
    7.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
    8.             'next the image will become a blank die so we can tell which dice we have chosen to change
    9.             clickCntrD1 = 0
    10.         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.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  5. #5
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Picturebox click event handling.

    I fixed your code here:

    VB Code:
    1. If clickCntrD1 = 0 Then
    2.             clickCntrD1 += 1
    3.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.Fixed3D
    4.             'next the image will become a blank die so we can tell which dice we have chosen to change
    5.         Else
    6.             pbxDieOne.BorderStyle = pbxDieOne.BorderStyle.None
    7.             'next the image will become a blank die so we can tell which dice we have chosen to change
    8.             clickCntrD1 = 0
    9.         End If
    Last edited by <ABX; Feb 1st, 2005 at 11:57 PM. Reason: Did i mention that i hate this editor :P
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  6. #6

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    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
    Last edited by gjon; Feb 2nd, 2005 at 01:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width