In my form, I have a panel
with picture boxes on it. When the mouse hovers over the panel
the picture boxes should show. When the mouse leaves, the picture boxes should hide.
At first I tried
panel1.visible = true;
and
panel1.visible = false;
I thought this would do, but it doesn't work. Then I tried the following method
namespace Drawing_Program
{
public partial class Form1 : Form
{
PictureBox[] Boxes = new PictureBox[12];
public Form1()
{
InitializeComponent();
int i = 0;
foreach (var pb in Controls.OfType<PictureBox>())
{
Boxes[i] = pb;
i++;
}
}
private void panel1_MouseHover(object sender, EventArgs e)
{
for (int i = 0; i < Boxes.Length; i++) {
this.Boxes[i].Visible = true; // error gives here
}
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
for (int i = 0; i < Boxes.Length; i++)
{
this.Boxes[i].Visible = false;
}
}
but I am getting the following error:
nullreferenceException was unhandled: Object reference not set to an instance of an object.
Please tell me what is wrong or how to do this properly.