我正在尝试创建一个程序来读取一些值,分析它们并绘制结果。我无法让情节工作,这可能是由于错误的参数被发送到我的情节类。
这就是我在Form类中的内容:
private void FileButton_Click(object sender, EventArgs e)
{
OpenFileDialog ReadFileDialog = new OpenFileDialog();
if (ReadFileDialog.ShowDialog() == DialogResult.OK)
{
ReadFile Acceleration = new ReadFile();
if (PlotResultCheckbox.Checked)
{
PlotClass PlotResult = new PlotClass();
//The FormClass being the class I'll call to plot from various part of my program
PlotResult.FFTPlot();
}
}
}
private void FFTPlotWindow_Load(object sender, EventArgs e)
{
//Don't really know what to put here but this is my Plot-window anyway
}
除了我将绘制的数据的明显参数之外,我应该将哪些参数传递给我的Plot类?我应该公开FFTPlotWindow吗?
提前致谢 阿克塞尔
答案 0 :(得分:1)
为了实现您的目标,我可以提出两种方法。
在这种情况下,PlotClass应该知道它。
您可以在FFTPlot方法中指定对ZedGraph控件的引用,该方法应该绘制图形。
public class PlotClass
{
...
public void FFTPlot(ZedGraphControl zgc)
{
// Build the point list and attach it to a new curve
GraphPane myPane = zgc.GraphPane;
var list = new PointPairList();
// Your code to add the points
// ...
var myCurve = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.None);
zgc.AxisChange();
zgc.Invalidate();
}
}
然后:
if (PlotResultCheckbox.Checked)
{
PlotClass PlotResult = new PlotClass();
PlotResult.FFTPlot(zedGraphControl1);
}
所以:
if (PlotResultCheckbox.Checked)
{
PlotClass PlotResult = new PlotClass();
GraphPane myPane = zedGraphControl1.GraphPane;
var list = new PointPairList();
// Your code to add the points using a property exposed by PlotResult
// ...
var myCurve = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.None);
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
}
无论您决定哪种方法,the ZedGraph wiki都会非常有用。