C# - OxyPlot如何向Windows窗体添加绘图

时间:2014-11-04 22:15:11

标签: c# oxyplot

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

3 个答案:

答案 0 :(得分: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;

答案 1 :(得分:4)

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

答案 2 :(得分:2)

我自己就是这个问题。我尝试添加Reference(右键单击Solution Explorer中的References,然后浏览“OxyPlot.dll”和“OxyPlot.WindowsForms.dll”文件。)起初它不起作用;不断出错。

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

我现在在工具箱中有Pointer和PlotView。我正在使用带有Forms应用程序的VS2017社区。上面的手册版也适用于我。