2

I have a panel that contains child panels an inside the child panels I have some controls like PictureBox and label.

How can I change the back colour of just one child panel that mouse pointer is pointing with foreach and how can I change the colour of selected panel child and how can I create child panels inside the panel that contain PictureBox and label?

There will be problems if there is no (or small) space between Parent Control (Panel) edge and Child Control that the mouse pointer should be on the right side of the child panel to work. How can i fix this? this is my code for the mouseleave event:

private void left_panel_MouseLeave(object sender, EventArgs e)
{
  foreach (Panel p in left_panel.Controls.OfType<Panel>())
  {
    p.BackColor = Color.Transparent;
  }
}

Mouse Enter Event:

private void left_panel_MouseEnter(object sender, EventArgs e)
{
  foreach (Panel p in left_panel.Controls.OfType<Panel>())
  {
    if (this.ClientRectangle.Contains(p.PointToClient(Control.MousePosition)))
    {
      p.BackColor = ColorTranslator.FromHtml("#ff0000");
    }
    else
      p.BackColor = Color.Transparent;
  }
}

This is what i have: My Program

I want something like this: xbox beta windows 10 app

  • While you can use handle mouse events of child controls like [this post](https://stackoverflow.com/a/50886066/3110834), I recommend using a `ToolStrip` or `MenuStrip` or at least, using button/radio button instead of a trying to simulate a button using panel containing picturebox and label. Take a look at [this post](https://stackoverflow.com/a/36252030/3110834). – Reza Aghaei Jul 03 '18 at 03:25
  • I Used FlowLayoutPanel. Now I want to arrange buttons at runtime with drag and drop. – Ali Mohammadi Jul 06 '18 at 03:22

0 Answers0