10

试用 OxyPlot,安装和引用包。从此处复制并粘贴示例http://docs.oxyplot.org/en/latest/getting-started/hello-windows-forms.html但它无法plot1从最后一行识别。我猜是因为控件没有添加到表单中。我该如何添加它?我在工具箱中看不到它,我尝试将控件添加到工具箱中,但在任何地方都找不到。谢谢。

4

3 回答 3

5

您可以通过在表单设计器中的初始化组件方法下附加这些行来手动添加绘图控件。

private void InitializeComponent()
{
    this.plot1 = new OxyPlot.WindowsForms.PlotView();
    this.SuspendLayout();
    // 
    // plot1
    // 
    this.plot1.Dock = System.Windows.Forms.DockStyle.Bottom;
    this.plot1.Location = new System.Drawing.Point(0, 0);
    this.plot1.Name = "plot1";
    this.plot1.PanCursor = System.Windows.Forms.Cursors.Hand;
    this.plot1.Size = new System.Drawing.Size(500,500);
    this.plot1.TabIndex = 0;
    this.plot1.Text = "plot1";
    this.plot1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
    this.plot1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
    this.plot1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
    this.Controls.Add(this.plot1);

    //
    // other comtrols
    //

}
private OxyPlot.WindowsForms.PlotView plot1;
于 2014-11-12T06:43:10.540 回答
4

您说“我尝试将控件添加到工具箱中,但在任何地方都找不到。”。它可能没有找到您安装的 Oxyplot.WindowsForms。在 Visual Studio 项目中,右键单击工具箱区域后,单击“.Net Framework Components”,然后单击“浏览”并找到“OxyPlot.WindowsForms.dll”。如果您将它安装到您的项目中,它应该位于包子文件夹之一中,例如 packages\\lib 文件夹。

于 2016-04-14T23:52:03.837 回答
2

我自己也有这个问题。我尝试添加参考(在解决方案资源管理器中右键单击参考,然后浏览“OxyPlot.dll”和“OxyPlot.WindowsForms.dll”文件。)起初它不起作用;一直报错。

我注意到“Oxyplot.dll”有两个版本;一个 net40 和一个 net45。我最初使用的是 net45 版本。我将 net40 版本复制到与“OxyPlot.WindowsForms.dll”相同的位置,添加了参考,转到工具箱,添加一个新选项卡,然后添加对选项卡的引用(右键单击选项卡 -> 选择项目,然后搜索 Oxyplot)。

我现在在工具箱中有 Pointer 和 PlotView。我正在使用带有表单应用程序的 VS2017 社区。上面的手动版本也对我有用。

于 2017-07-03T20:12:31.197 回答