This is my very first thread on the net period, I'll do my best to describe my c# problem. I was wondering if there is any way of calling upon general event trigger objects (referring to buttons, picture box etc.) on a whole, for example is there a keyword that i can use to do this.
I want multiple picture boxes to be handled by one event and I want to be able to make each picture box invisible when I move the mouse over it, without having to name the picture boxes individually. Is this possible?

>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;
            ....
        }

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.

Thanks for my first replies :), i've established how to link multiple events before and have used it in another section of my code. But what I want to do is set up the event handler to make any object that I assign to it (eg. a picture box) go invisible. At the moment i have an event for each picture box which looks like this...

private void picturebox1_MouseMove(object sender, MouseEventArgs e)
{picturebox1.visibility = false;
}

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;
   }
}

It's working, :)thanks a lot. Minimized my code dramatically.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.