Jixi
Jixi

Reputation: 117

Getting mouse enter event on full panel c#

So what i have is a panel that's programmatically filled with custom controls using DockStyle.Top.

What i need is for the panel to get focus somehow when mouse cursor enters the panel so that the user can use mousewheel to scroll the panel.

I don't really want to give each control a handler because there could be hundreds of controls.

One way could be checking for mouse position and check if the panel contains it, which would probably require an extra thread or mousehook but perhaps there's a better way?

Upvotes: 0

Views: 1289

Answers (1)

Alex Filipovici
Alex Filipovici

Reputation: 32541

You may implement the MouseDetector class posted by Amen Ayach as an answer to a similar question and activate the form when the mouse hovers it:

void m_MouseMove(object sender, Point p)
{
    Point pt = this.PointToClient(p);
    if (this.ClientSize.Width >= pt.X &&
                    this.ClientSize.Height >= pt.Y &&
                    pt.X > 0 && pt.Y > 0)
    {
        this.Activate();
    }
}

You should also set the Panel's AutoScroll value to true.

panel.AutoScroll = true;

Upvotes: 2

Related Questions