[英]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.