Hide multiple PictureBox except clicked
HI
Let me explain what i want to do.
I have a Form
with 10 PictureBoxes
on it.
When I click
at one of them I want to hide all other except the click开发者_开发技巧ed one.
It is possible that on ClickEvent
of all of them hide others.but I ask for efficent way.for example with a single function call from click event maybe.
I do not have .net installed on this computer but here is my solution.
Create a Tag for each control, then select all 10 pictureboxes and create one click event for them.
in the click event you can use this code, to loop through all controls and only hide the pictureboxes.
foreach (Control ctrl in Form1.Controls)
{
if (ctrl.GetType() == typeof(PictureBox))
{
if (((PictureBox)ctrl).Tag == ((PictureBox)sender).Tag)
{
ctrl.Hide();
}
else
{
ctrl.Show();
}
}
}
You might be able to compare the objects without Tags, but i can not test this without c# installed.
Just write a function that accepts the Object. In that function you can loop through all those pictureboxes and compare it to the Object. If it's the Sender object you don't hide, otherwise you will.
精彩评论