Hello Niels,
If you have subscribed to MouseDown/MouseClick events for both the chart and the annotation, they will both trigger. This cannot be prevented. However, there are several ways to prevent the code inside the chart's event to execute when an Annotation is clicked.
-If you are using the same event type (MouseClick, MouseDown etc.) for the chart and the Annotations, the event for the Annotations triggers first. You can add a simple boolean variable, which is set true inside the Annotation event. Then use this to prevent the chart event.
Code: Select all
private void Anno_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
annoClicked = true;
// Do something
}
}
private void _chart_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (!annoClicked)
{
// Do something
}
else
{
annoClicked = false;
}
}
}
-If your chart uses MouseDown event while the Annotation use MouseClick event as is seen in your code sample, the above will not work since MouseDown is always triggered before MouseClick. In this case, you can check inside the chart's event if the current location is over an Annotation.
Code: Select all
private void _chart_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
bool isOver = false;
foreach (var anno in _chart.ViewXY.Annotations)
{
if (anno.IsPositionOver(e.X, e.Y))
{
isOver = true;
}
}
if (!isOver)
{
// Do something
}
}
}
With the above, it is actually possible to not subscribe to any events for the Annotations. You could execute the Annotation click code if IsPositionOver hits true.
Best regards,
Lasse