private int GetButtonIndexByLocation(Point xy)
{
var rBp = ButtonPanel;
if (xy.X >= rBp.X && xy.Y > rBp.Y && xy.X <= rBp.X + rBp.Width && xy.Y <= rBp.Y + rBp.Height)
{
double x = xy.X - rBp.X;
return Convert.ToInt32(Math.Ceiling((x / rBp.Width) * ButtonCount)) - 1;
}
return -999;//nothing
}