|
-
Oct 18th, 2003, 06:45 PM
#1
Thread Starter
New Member
[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.
-
Oct 18th, 2003, 06:48 PM
#2
Lively Member
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."
-
Oct 18th, 2003, 07:25 PM
#3
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!!
-
Oct 20th, 2003, 04:08 AM
#4
Thread Starter
New Member
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.
-
Oct 20th, 2003, 06:50 PM
#5
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:
' hint hint use a smaller array size :rolleyes:
dim pics(10000000000000) as picturebox
sub foo
for i= 0 to 10000000000000
pics(i) = new picturebox
pics(i).tag = i 'save the index of the picturebox
' I hope this is the right syntax :). Basically it's registering the MouseClick event with the given sub
addHandler pics(i).MouseClick, AddressOf pic_MouseClick
next
me.controls.addrange pics
end sub
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
dim aPicBox as picturebox = directcast( sender, picturebox)
dim index as integer = int.parse(apicbox.tag)
' 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.
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!!
-
Oct 22nd, 2003, 02:54 AM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|