Click here to Skip to main content
15,906,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: Ayo game Pin
egenis22-Apr-12 0:13
egenis22-Apr-12 0:13 
GeneralRe: Ayo game PinPopular
DaveyM6920-Apr-12 6:33
professionalDaveyM6920-Apr-12 6:33 
Questionaspxgridview,checkbox and check all Pin
tomorrow_ft20-Apr-12 1:01
tomorrow_ft20-Apr-12 1:01 
AnswerRe: aspxgridview,checkbox and check all Pin
Karthik Harve20-Apr-12 1:23
professionalKarthik Harve20-Apr-12 1:23 
GeneralRe: aspxgridview,checkbox and check all Pin
tomorrow_ft20-Apr-12 3:02
tomorrow_ft20-Apr-12 3:02 
Questionneed help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
ronensv19-Apr-12 23:54
ronensv19-Apr-12 23:54 
AnswerRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
Wes Aday20-Apr-12 0:42
professionalWes Aday20-Apr-12 0:42 
AnswerRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
Sentenryu20-Apr-12 1:19
Sentenryu20-Apr-12 1:19 
GeneralRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
Wes Aday20-Apr-12 1:25
professionalWes Aday20-Apr-12 1:25 
GeneralRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
Sentenryu20-Apr-12 1:32
Sentenryu20-Apr-12 1:32 
GeneralRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
ronensv20-Apr-12 6:05
ronensv20-Apr-12 6:05 
GeneralRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
Sentenryu20-Apr-12 9:46
Sentenryu20-Apr-12 9:46 
GeneralRe: need help with implemnet conecction between c# app in windows to linux SLES 10 serve Pin
jschell20-Apr-12 10:23
jschell20-Apr-12 10:23 
QuestionHow to send array of objects to restful client as parameters Pin
NarVish19-Apr-12 22:09
NarVish19-Apr-12 22:09 
QuestionHow to register a new List<IChecker> to Actofac ContainerBuilder Pin
Johan Bertilsdotter19-Apr-12 21:25
Johan Bertilsdotter19-Apr-12 21:25 
AnswerRe: How to register a new List to Actofac ContainerBuilder Pin
Dave Kreskowiak20-Apr-12 3:30
mveDave Kreskowiak20-Apr-12 3:30 
Questioncreating event handler for picturebox click event Pin
Member 857219719-Apr-12 13:10
Member 857219719-Apr-12 13:10 
AnswerRe: creating event handler for picturebox click event Pin
DaveyM6919-Apr-12 14:47
professionalDaveyM6919-Apr-12 14:47 
QuestionRe: creating event handler for picturebox click event Pin
Member 857219720-Apr-12 4:32
Member 857219720-Apr-12 4:32 
QuestionRe: creating event handler for picturebox click event Pin
DaveyM6920-Apr-12 6:23
professionalDaveyM6920-Apr-12 6:23 
AnswerRe: creating event handler for picturebox click event Pin
Member 857219720-Apr-12 6:36
Member 857219720-Apr-12 6:36 
AnswerRe: creating event handler for picturebox click event Pin
DaveyM6920-Apr-12 7:05
professionalDaveyM6920-Apr-12 7:05 
No, that isn't possible - but it doesn't sound like a good way to me anyway. The += needs a EventHandler delegate instance as a parameter. This can be done by using either an existing instance, a new instance or just a method name with the correct signature.

Have you considered an alternative aproach - and using one event handler for all the picture boxes?
You can attach the event handler to all PictureBoxes in a simple loop:
C#
foreach (Control control in this.Controls)
    if (control is PictureBox)
        control.Click += PictureBoxClickHandler;

and your handling method would start like this:
C#
private void PictureBoxClickHandler(object sender, EventArgs e)
{
    PictureBox pictureBox = sender as PictureBox;
    if (pictureBox != null)
    {
        // pictureBox is the PictureBox that was clicked.
        // Do your stuff
    }
}

You can now use any property (perhaps Name as you want to use strings, the Tag property is designed for this though) to identify the picture box in question and react as you wish. I usually prefer to subclass the control and add an Id property:
C#
public class MyPictureBox : PictureBox
{
    private int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }
}

C#
foreach (Control control in this.Controls)
    if (control is MyPictureBox)
        control.Click += MyPictureBoxClickHandler;

C#
private void MyPictureBoxClickHandler(object sender, EventArgs e)
{
    MyPictureBox myPictureBox = sender as MyPictureBox;
    if (myPictureBox != null)
    {
        switch (myPictureBox.Id)
        {
            case 1:
                // do stuff for 1
                break;
            case 2:
            case 3:
                // do stuff for 2 and 3
                break;
            default:
                // default id (0)
                break;
        }
    }
}

[Edit] You would obviously need to use MyPictureBoxes instead of the built in PictureBox. After a build, it will show in your toolbox for drag and drop - or you can just change the code where they are created.
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: creating event handler for picturebox click event Pin
Member 857219720-Apr-12 7:11
Member 857219720-Apr-12 7:11 
QuestionDodger Game in C# Pin
Qobacha19-Apr-12 9:26
Qobacha19-Apr-12 9:26 
AnswerRe: Dodger Game in C# Pin
Eddy Vluggen19-Apr-12 9:49
professionalEddy Vluggen19-Apr-12 9:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.