也许问题很简单,但是我在WinForms中使用OpenTK,问题是我在工具箱中找不到GLcontrol,所以我在Form1.Designer.cs中手动添加了它,这是代码
#region Windows窗体设计器生成的代码
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
glcontrol1 = new OpenTK.GLControl();
this.SuspendLayout();
//
// glControl1
//
//
// Form1
//
this.Controls.Add(glcontrol1);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 561);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
OpenTK.GLControl glcontrol1;
问题是当我在设计模式下打开Form1时,它显示了这些消息
“无法从程序集中加载类型OpenTK.ToolkitOptions …”
“未声明或未分配变量glcontrol1”
我想要一种将GLcontrol添加到工具箱的方法,有人知道吗?
解决方法:
仔细检查您的项目引用,您需要同时使用OpenTK.dll和OpenTK.GLControl.dll.
文档中的“Building a Windows.Forms + GLControl based application”涵盖了将GLControl添加到WinForms工具箱中.
To begin with, create a Form on which you will place your GLControl. Right click in some empty space of the Toolbox, pick “Choose Items…” and browse for
OpenTK.GLControl.dll
. Make sure you can find the “GLControl” listed in the “.NET Framework Components”, as in the image below.
Then you can add the GLControl to your form as any .NET control. A GLControl named glControl1 will be added to your Form.