Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MouseEnter & MouseLeave objectname

I want to add MouseOver and MouseLeave events to dynamical created panels in a flowLayoutPanel.

I added all panels in a list named "panels" and they are accessible with "panels[index]".

Now I want to dynamical add a MouseOver and MouseLeave event to each panel. I thought it could be possible to get the panelname the Mouse is over and use just one method for each event and identify the panel the mouse is over with its panelname (panel.Name) but I found nothing in "sender".

Is there a way to do this?

My code:

//Method
private void PanelsMouseEnter(object sender, EventArgs e)
{
    var panel = sender as Control;
    foreach (Control control in this.fLpKoerper.Controls)
    {
        if (control.Name == panel.Name)
        {
            foreach (Panel panels in panelsKoerper)
            {
                if (panels.Name == panel.Name)
                    panels.BackColor = Color.DarkGray;
            }
        }
    }  
}

//Event
panelsKoerper[y].MouseEnter += PanelsMouseEnter;
like image 577
kryptex Avatar asked Feb 03 '26 06:02

kryptex


1 Answers

var panel = sender as Control;
var thePanelName = panel.Name;
like image 105
Adam Barney Avatar answered Feb 04 '26 18:02

Adam Barney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!