如何检索在净的WinForms图表控件选择的范围? [英] How to retrieve the selected range in the .Net WinForms Chart Control?

查看:380
本文介绍了如何检索在净的WinForms图表控件选择的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是内置的WinForms图表控件的C#(的 System.Windows.Forms.DataVisualization.Charting.Chart ),其内置的让用户选择一个范围的能力。我想要做的就是回读什么范围用户选择。

I'm using the C# built-in Winforms Chart control (System.Windows.Forms.DataVisualization.Charting.Chart) with its built-in ability to let the user select a range. What I'd like to do is to read back what range the user has selected. Surely there must be some easy way to do this, but I haven't been able to find it.

光标像这样启用
$ b

The cursor is enabled like so:

var ca = chart1.ChartAreas["ChartArea1"].CursorX;
ca.CursorX.IsUserEnabled = true;
ca.CursorX.IsUserSelectionEnabled = true;



我知道,我可以让图表变焦当用户选择一个范围内启用 ca.AxisX.ScaleView.Zoomable ,但我不希望画面改变:不是我使用的图表,以此来显示信息,让用户选择x的范围。值,然后我做一些额外的处理。

I am aware that I can make the chart zoom when the user selects a range by enabling ca.AxisX.ScaleView.Zoomable, but I don't want the picture to change: instead I am using the chart as a way to display information and let the user select a range of X values for which I then do some extra processing.

我试图向挂钩和chart1.SelectionRangeChanged的确触发间隔的范围改变时 - 我只是不能似乎您可以通过CursorEventArg我找回了选择范围。它有 NewSelectionStart NewSelectionEnd 领域,但这些都是 NaN的,令人失望。我试着看图表和轴的各种属性,但没有发现任何东西,听起来前途

I tried hooking to chart1.SelectionRangeChanged and that indeed fires every time the range is changed - I just can't seem to get the selection range from the CursorEventArg I get back. It has "NewSelectionStart" and "NewSelectionEnd" fields, but those are NaN, disappointingly. I tried looking at the various properties of the chart and the axes, but didn't find anything that sounded promising.

进一步的调查揭示的 ChartArea.CursorX.SelectionStart 属性,它听起来像正是我需要什么......除了它的NaN的了。我不知道这是否正常,或者我打某种错误的?

Further investigation reveals the ChartArea.CursorX.SelectionStart property which sounds like exactly what I need... except that it's NaN too. I don't know whether this is normal or I'm hitting some sort of bug?

所以,我怎么能弄清楚范围用户选择什么呢?

So, how can I figure out what range the user selected?

推荐答案

好吧,好吧,我想通了。这里的独家新闻:

OK, well, I figured it out. Here's the scoop:

有一个SelectionRangeChang *的 ING 的*事件,当一个运行 ChartArea.CursorX。 SelectionStart ChartArea.CursorX.SelectionEnd 字段在他们正确的价值观。但用户并没有释放鼠标按键还,所以你应该只是存储它们。

There's a SelectionRangeChang*ing* event, and when that one runs the ChartArea.CursorX.SelectionStart and ChartArea.CursorX.SelectionEnd fields have correct values in them. But the user hasn't released the mouse button yet, so you should just store them.

当用户释放鼠标按钮时,SelectionRangeChang *的 ED 的*事件触发。不知怎的,它的设计以这样一种方式,SelectionStart和选定结束被重置为NaN(就像 NewSelectionStart NewSelectionEnd 的领域事件参数)。你所要做的就是用你从其他的事件处理程序squirreled走现在你知道时间是正确使用它们的值。

When the user releases the mouse button, the SelectionRangeChang*ed* event fires. Somehow it's designed in such a way that SelectionStart and SelectionEnd are reset to NaN (just like the NewSelectionStart and NewSelectionEnd fields in the event parameters). What you have to do is to use the values that you squirreled away from the other event handler now that you know the time is right to use them.

所以你有它!希望这个答案将节省的人浪费时间别的。

So there you have it! Hopefully this answer will save someone else from wasting time.

这篇关于如何检索在净的WinForms图表控件选择的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆