MSChartControl 选择时的奇怪行为

发布于 2024-11-28 08:17:20 字数 1027 浏览 13 评论 0原文

我在我的应用程序中使用 MSChartControl。在图表控件中,我显示一个图像,我想使用图表控件的选择机制来使用 ChartArea 中的 CursorX 选择图像范围。

在 SelectionRangeChanged 事件中,我想在用户完成选择时收到通知,然后我想对尚未选择的区域进行着色并隐藏原始选择。

由于没有ClearSelection(至少我还没有找到这样的方法),我将选择设置为未完成选择时光标最初具有的值:

private void chartTopoAP_SelectionRangeChanged(object sender, CursorEventArgs e)
{
    int Start = (int)e.NewSelectionStart;
    int End = (int)e.NewSelectionEnd;

    MathUtil.SwapIf(Start > End, ref Start, ref End);

    mySelectedRange = new Tuple<int, int>(Start, End);

    chartTopoAP.ChartAreas[0].CursorX.SetSelectionPosition(double.NaN, double.NaN);
    chartTopoAP.Invalidate();
    chartTopoAP.Update();
}

在paint方法中我自己进行绘画。

除非我调整窗口和图表控件的大小,否则这似乎有效。

1)我启动窗口,然后选择一些内容 2)我调整图表控件的大小(更大/更小并不重要) 3)我做了另一个选择

->结果是,显然该控件已在内部缓冲了一些图形,并向我显示了调整控件大小之前的图表大小。

如果我注释掉该行,

chartTopoAP.ChartAreas[0].CursorX.SetSelectionPosition(double.NaN, double.NaN);

它就可以工作。但我该如何清除选择呢?

谢谢 马丁

I'm using the MSChartControl in my application. In the chart control I display an image where I want to use the selection mechanism of the chart control to select a range of the image using the CursorX from the ChartArea.

In the SelectionRangeChanged event I want to get informed when a selection has been done by the user and then I want to colorize the areas that haven't been selected and hide the original selection.

Since there is no ClearSelection (at least I haven't found such a method), I set the selection to a value that the Cursor initially had when no selection was done:

private void chartTopoAP_SelectionRangeChanged(object sender, CursorEventArgs e)
{
    int Start = (int)e.NewSelectionStart;
    int End = (int)e.NewSelectionEnd;

    MathUtil.SwapIf(Start > End, ref Start, ref End);

    mySelectedRange = new Tuple<int, int>(Start, End);

    chartTopoAP.ChartAreas[0].CursorX.SetSelectionPosition(double.NaN, double.NaN);
    chartTopoAP.Invalidate();
    chartTopoAP.Update();
}

In the paint method I do my own painting.

This is seems to work unless I resize the window and the chartcontrol.

1) I start the window, and select something
2) I resize the chartcontrol (larger/smaller doesn't matter)
3) I do another selection

-> The result is, that obviously the control has buffered some graphics internally and shows me the chart with a size that I had before resizing the control.

If I comment out the line

chartTopoAP.ChartAreas[0].CursorX.SetSelectionPosition(double.NaN, double.NaN);

it works. But how would I clear a selection then?

Thanks
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2024-12-05 08:17:20

这似乎与scaleview缩放设置有关。如果在重置选择后添加

chartTopoAP.ChartAreas[0].AxisX.ScaleView.ZoomReset();

,症状就会消失。

It seems to be related to scaleview zoom settings. if you add

chartTopoAP.ChartAreas[0].AxisX.ScaleView.ZoomReset();

after reseting the selection, the symptom goes away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文