Results 1 to 6 of 6

Thread: [Resolved] click event on controls created run time?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    3

    [Resolved] click event on controls created run time?

    I'm creating several pictureboxes in run time and want to know which has been clicked?

    This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).

    Thanks.
    Last edited by Briansol; Oct 22nd, 2003 at 02:55 AM.

  2. #2
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108

    Your problem is yet to be solved

    Originally posted by Briansol
    I'm creating several pictureboxes in run time and want to know which has been clicked?

    This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).

    Thanks.
    Are you using an array of pictureboxes?
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Briansol
    I'm creating several pictureboxes in run time and want to know which has been clicked?

    This is kind of a card game where is picturebox holds an image of a card and I want to know which card the user want to play(click).

    Thanks.
    in the click event , the Sender parameter is the picturebox. You will have to convert it to a picturebox though:

    dim aPicBox as picturebox = directcast( sender, picturebox)

    that would give you the clicked picturebox. Now to distinguish between them, you could either check the name of the picturebox, or you could use the .Tag property.
    For example you could save the index of each picturebox when you are creating them in the Tag property of the picturebox. then when the user clicks on one of them, use Cint(aPicBox.Tag) to get the index. (That is, if you are using a control array for your pictureboxes)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    3
    Thanks,

    I'm using an array for my pictureboxes, but how do I code the click event for the array? I can only get it working a variable with WithEvents.

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    oh hehe
    use the AddHandler function, it's wonderful


    dont have VS to test it, but I think something like this should work"

    VB Code:
    1. ' hint hint use a smaller array size :rolleyes:
    2.      dim pics(10000000000000) as picturebox
    3.  
    4. sub foo
    5.      for i= 0 to 10000000000000
    6.          pics(i) = new picturebox
    7.          pics(i).tag = i   'save the index  of the picturebox
    8.          
    9.          ' I hope this is the right syntax :). Basically it's registering the MouseClick event with the given sub
    10.          addHandler pics(i).MouseClick, AddressOf pic_MouseClick
    11.          
    12.      next
    13.      me.controls.addrange pics
    14. end sub
    15.  
    16. private sub pic_MouseClick ( ??? ,  ??? )   ' Look up a picturebox's mouse click event and just use that. I dont know what the arguments are. Probably just a Sender As Object variable and a MouseEvents arg
    17.  
    18.    dim aPicBox as picturebox = directcast( sender, picturebox)
    19.    dim index as integer = int.parse(apicbox.tag)
    20.  
    21.    ' that gives you the index, if it is of any use... you could just use aPicBox to access the picturebox, or pics(index), same thing.
    22. end sub

    HTH
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    3
    Got it working.

    Thanks a lot

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