today
0
Q:

c# picturebox array how to create handler mouseover for element

//You need simply write

pbs[i].MouseEnter += globalMouseEnterEvent;
//of course you need to have a globalMouseEnterEvent somewhere in your code

public void globalMouseEnterEvent(object sender, System.EventArgs e)
{
    ....
}
//However, another piece of information is needed when your work with event shared between numerous controls. You need to recognize the control that triggers the event. The control instance is passed using the sender parameter that you can cast to your appropriate control type, but what is needed is to give a unique identifier to your control. Like setting the Tag or Name properties when you build the control

for (int i = 0; i < pbs.Length; i++)
{
  .....
  pbs[i].Tag = "PB" + i.ToString()
  ...
}
//so in the MouseEnter code you could write

public void globalMouseEnterEvent(object sender, System.EventArgs e)
{
    PictureBox p = sender as PictureBox;
    if(p.Tag.ToString() == "PB1")
        .....
    else if ......
}
1
//You need simply write

pbs[i].MouseEnter += globalMouseEnterEvent;
//of course you need to have a globalMouseEnterEvent somewhere in your code

public void globalMouseEnterEvent(object sender, System.EventArgs e)
{
    ....
}
1

New to Communities?

Join the community