http://www.opentk.com/node/4026
1) Run WinForm and GameWindow App in two different thread as below
1) Run WinForm and GameWindow App in two different thread as below
using System; using System.Threading; using System.Windows.Forms; using Debug = System.Diagnostics.Debug; using OpenTK; using OpenTK.Graphics.OpenGL; namespace OpenTKWinForms { class MainClass { static GameWindow window; static Form form; static OpenTK.Graphics.Color4 color; public static void Main(string[] args) { // OPTION 1: Start windows form in a new thread. // Form is created either here or inside ThreadStart. // form = new Form(); // form.Click += Form_Click; // var threadForm = new Thread(new ThreadStart(() => { // form = new Form(); // form.Click += Form_Click; // Application.Run(form); // })); // threadForm.Start(); // window = new GameWindow(); // window.RenderFrame += Window_RenderFrame; // window.Run(2.0, 2.0); // OPTION 2: Start OpenTK window in a new thread. // var threadOpenTK = new Thread(new ThreadStart(() => { // window = new GameWindow(); // window.RenderFrame += Window_RenderFrame; // window.Run(2.0, 2.0); // })); // threadOpenTK.Start(); // // form = new Form(); // form.Click += Form_Click; // Application.Run(form); } static void Form_Click (object sender, EventArgs e) { var r = new Random(); var c1 = new float[] { (float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble() }; var c2 = new int[] { (int)(c1[0] * 255), (int)(c1[1] * 255), (int)(c1[2] * 255) }; color = new OpenTK.Graphics.Color4(c1[0], c1[1], c1[2], 1f); form.BackColor = System.Drawing.Color.FromArgb(c2[0], c2[1], c2[2]); } static void Window_RenderFrame (object sender, FrameEventArgs e) { GL.ClearColor(color); Debug.WriteLine(color); GL.Clear(ClearBufferMask.ColorBufferBit); window.SwapBuffers(); } } }