>I want multiple picture boxes to be handled by one event ..
You want to write single event handler for multiple picture boxes.
private void Form1_Load(object sender, EventArgs e)
{
picture1.MouseEnter += new EventHandler(MyHandler);
picture2.MouseEnter+=new EventHandler(MyHandler);
}
void MyHandler(object sender, EventArgs e)
{
PictureBox currentPic = sender as PictureBox;
....
}
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
adatapost's answer is right.
You can attach the events of all the picture boxes in one go.
After coding your event handler for one of the picture boxes select all the picture boxes.
On the properties window select the events button at the top and scroll to find the MouseEnter event.
Click on the drop-down arrow and select the newly code MouseEnter event handler.
Now all the picture boxes are attached to the event handler in the forms InitializeComponent() function.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
For events the sender object is the object triggering the event.
Try this.
private void picturebox1_MouseMove(object sender, MouseEventArgs e)
{
PictureBox pb = sender as PictureBox;
if(pb !=null)
{
pb.visibility = false;
}
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187