I have a chart (myChart) and more ChartArea in MyArea that is the ChartAreasCollection. I have to determinate if a double click is made in a certain ChartArea of the collection for select it. With the code written below every ChartArea has the same values for limits (x,y) so the if-condition is always true, even if the click was done on the first area.
Every chartarea can be visible or not so for use this function I have to check with the counter ActiveAreas if are visible more then one.
private void chartInForm_DoubleClick(object sender, EventArgs e)
{
if (ActiveAreas > 1)
{
Point mouse = ((MouseEventArgs)e).Location;
foreach (ChartArea ca in MyArea)
{
if (mouse.X > ca.Position.X &&
mouse.X < ca.Position.X + ca.Position.Width * myChart.Width / 100 &&
mouse.Y > ca.Position.Y &&
mouse.Y < ca.Position.Y + ca.Position.Height * myChart.Height / 100)
MessageBox.Show(ca.Name);
}
}
}