Post: Calling Certain Pictureboxes
03-06-2017, 03:50 AM #1
KrazyKandy
I am error
(adsbygoogle = window.adsbygoogle || []).push({}); Hello, I had someone from here help me call pictureboxes with images from my resources, but I want each picturebox to have its own click and do something different. Can anyone help me?
You must login or register to view this content.
03-07-2017, 06:30 AM #2
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
Hello, I had someone from here help me call pictureboxes with images from my resources, but I want each picturebox to have its own click and do something different. Can anyone help me?
You must login or register to view this content.


I made a thread about something like this a few years ago in VB.NET
You can refer to it here:
You must login or register to view this content.


What you want to look for is the AddHandler since you want to add functionality to the the controls. C# isn't exactly the same since it doesn't have addhandler but you get the idea. For instance for your picture box:

    
Images[i].Click += new EventHandler(pictureBox_Click);

void pictureBox_Click(object sender, EventArgs e)
{
//Do Stuff
}


The above code will add that event to every picture box. If you need each one to do something different then you would test for the specific picture box in pictureBox_Click

The following user thanked Oneup for this useful post:

KrazyKandy
03-07-2017, 07:40 PM #3
KrazyKandy
I am error
Originally posted by Oneup View Post
I made a thread about something like this a few years ago in VB.NET
You can refer to it here:
You must login or register to view this content.


What you want to look for is the AddHandler since you want to add functionality to the the controls. C# isn't exactly the same since it doesn't have addhandler but you get the idea. For instance for your picture box:

    
Images[i].Click += new EventHandler(pictureBox_Click);

void pictureBox_Click(object sender, EventArgs e)
{
//Do Stuff
}


The above code will add that event to every picture box. If you need each one to do something different then you would test for the specific picture box in pictureBox_Click


Alright, how would I have it grab the specific image specifically?
03-07-2017, 08:30 PM #4
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
Alright, how would I have it grab the specific image specifically?


I have an example in the thread I linked you to. C# will be a little different but the idea would be the same.
03-07-2017, 09:49 PM #5
KrazyKandy
I am error
Originally posted by Oneup View Post
I have an example in the thread I linked you to. C# will be a little different but the idea would be the same.


I finally got it by using the images name, thank you
03-08-2017, 12:08 AM #6
Father Luckeyy
Retired - Lead Content Manager
Originally posted by KrazyKandy View Post
I finally got it by using the images name, thank you


Was your issue solved?
03-08-2017, 09:29 AM #7
KrazyKandy
I am error
Originally posted by Dr.
Was your issue solved?


Yes sir
03-08-2017, 09:32 AM #8
Kronos
Former Staff
Good to hear! be sure to thank oneup for his help.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo