繁体   English   中英

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

[英]C# - OxyPlot how to add plot to windows form

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

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

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;

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM