Thanks Narcís... that works.
I use it to popup a certain context menu whenever one of the axes is clicked.
Previously what I did was this:
Code: Select all
private void tChart_RightClick(object sender, MouseEventArgs e)
{
bool searchClick = false;
Axis[] axes = { tChart.Axes.Bottom, tChart.Axes.Left, tChart.Axes.Right, tChart.Axes.Top };
foreach (Axis selectedAxis in axes)
{
// Skip axis if it is not visible
if (!selectedAxis.Visible)
{
continue;
}
try
{
searchClick = selectedAxis.Clicked(e.X, e.Y);
}
catch (ArgumentException)
{
return;
}
if (searchClick)
{
// Show the context menu
axisContextMenuStrip.Tag = selectedAxis;
axisContextMenuStrip.Show(tChart, e.X, e.Y);
return;
}
}
}
I now changed it to this (to make it work with a polar = workaround you gave me + enhanced a little bit):
Code: Select all
private void tChart_RightClick(object sender, MouseEventArgs e)
{
int axisSpacing = 3;
// Bottom axis
if ((tChart.Axes.Bottom.Visible) &&
(e.Y >= tChart.Axes.Bottom.Position - axisSpacing && e.Y <= tChart.Axes.Bottom.Position + axisSpacing) &&
(e.X >= tChart.Axes.Bottom.IStartPos - axisSpacing && e.X <= tChart.Axes.Bottom.IEndPos + axisSpacing))
{
// Show the context menu
axisContextMenuStrip.Tag = tChart.Axes.Bottom;
axisContextMenuStrip.Show(tChart, e.X, e.Y);
return;
}
// Left axis
if ((tChart.Axes.Left.Visible) &&
(e.X >= tChart.Axes.Left.Position - axisSpacing && e.X <= tChart.Axes.Left.Position + axisSpacing) &&
(e.Y >= tChart.Axes.Left.IStartPos - axisSpacing && e.Y <= tChart.Axes.Left.IEndPos + axisSpacing))
{
// Show the context menu
axisContextMenuStrip.Tag = tChart.Axes.Left;
axisContextMenuStrip.Show(tChart, e.X, e.Y);
return;
}
// Right axis
if ((tChart.Axes.Right.Visible) &&
(e.X >= tChart.Axes.Right.Position - axisSpacing && e.X <= tChart.Axes.Right.Position + axisSpacing) &&
(e.Y >= tChart.Axes.Right.IStartPos - axisSpacing && e.Y <= tChart.Axes.Right.IEndPos + axisSpacing))
{
// Show the context menu
axisContextMenuStrip.Tag = tChart.Axes.Right;
axisContextMenuStrip.Show(tChart, e.X, e.Y);
return;
}
// Top axis
if ((tChart.Axes.Top.Visible) &&
(e.Y >= tChart.Axes.Top.Position - axisSpacing && e.Y <= tChart.Axes.Top.Position + axisSpacing) &&
(e.X >= tChart.Axes.Top.IStartPos - axisSpacing && e.X <= tChart.Axes.Top.IEndPos + axisSpacing))
{
// Show the context menu
axisContextMenuStrip.Tag = tChart.Axes.Top;
axisContextMenuStrip.Show(tChart, e.X, e.Y);
return;
}
}
Can you assure me that the effect of the latter is the same as the first one?
I don´t have access to the source code of the Clicked method, so I´m unable to see what factors are determining wether an axis is clicked or not. Maybe I´m forgetting something in my code here?
Hopefully it gets resolved in one of the future releases... the first piece of code is much compacter and cleaner.
Regards