Thursday, May 28, 2009

Panel Hit Test in C# winforms

Today i wanted to check whether user click in with in the context of the panel. Since panel doesnt provide hittest this is how to do it ..

private bool panel_hit_test(Panel panel, POINT point_test)
{

Rectangle rect = panel.RectangleToScreen(panel.ClientRectangle);


if ((point_test.x > rect.X && point_test.x < rect.X + rect.Width) &&
(point_test.y > rect.Y && point_test.y < rect.Y + rect.Height))
{
return true;
}
else
return false;
}

2 comments:

Anonymous said...

Thanks for posting this, you saved my a$$.

Anonymous said...

The Windows Forms Panels and Labels Controls are a set of container controls that can be used to build extendable and themable controls with attractive user interface design for your Windows Forms applications.