eugene.chepurnykh's picture

Not firing Load event for GLControl.

Project:The Open Toolkit library
Category:bug report

GLControl.Load fire never.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Version:0.9.9-2b» 0.9.x-dev

Thanks for testing, will try to make a bugfix release next week.

the Fiddler's picture


Version:0.9.x-dev» 0.9.9-3
Status:fixed» closed

Closing issues fixed in 0.9.9-3.

karlschiffmann's picture


I am still not getting the glControl Load event firing with 0.9.9-3 VS C# 8.0. Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace OpenTK_issue_TutorialOutdated
    public partial class Form1 : Form
        public Form1()
        private void Form1_Load(object sender, EventArgs e)
            this.ClientSize = new Size(640, 480);
        private void glControl1_Resize(object sender, EventArgs e)
            int w = glControl1.Width;
            int h = glControl1.Height;
            GL.Viewport(0, 0, w, h); // Use all of the glControl painting area
        private void glControl1_Paint(object sender, PaintEventArgs e)
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Vertex2(0, 0);
            GL.Vertex2(1, 0);
            GL.Vertex2(0, 1);
        private void glControl1_Load(object sender, EventArgs e)
and the Designer:
namespace OpenTK_issue_TutorialOutdated
    partial class Form1
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
            if (disposing && (components != null))
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
            this.glControl1 = new OpenTK.GLControl();
            // glControl1
            this.glControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.glControl1.BackColor = System.Drawing.Color.Black;
            this.glControl1.Location = new System.Drawing.Point(-1, 0);
            this.glControl1.Name = "glControl1";
            this.glControl1.Size = new System.Drawing.Size(297, 276);
            this.glControl1.TabIndex = 0;
            this.glControl1.VSync = true;
            this.glControl1.Load += new System.EventHandler(this.glControl1_Load);
            this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
            this.glControl1.Resize += new System.EventHandler(this.glControl1_Resize);
            // Form1
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Name = "Form1";
            this.Text = "Form1";
        private OpenTK.GLControl glControl1;
the Fiddler's picture


Version:0.9.9-3» 0.9.x-dev
Status:closed» fixed

Fixed in rev. 2371, can you please test if the fix works?

The previous fix (rev. 2281) caused the control to be prematurely initialized when the Size property was set. The VS designer always sets this property before hooking any events, which meant these events were never raised.

I've added a different workaround, which simply suppresses the Resize event until the control has been correctly initialized. This seems to work correctly here, but need confirmation.

karlschiffmann's picture


Downloaded the latest dated 10/21/2009... and the Load event still does not fire for me... will attach my two files... thanks.

Form1.Designer.cs2.51 KB
Form1.cs1.5 KB
the Fiddler's picture


You have two Load events:

  • glControl1_Load fires correctly
  • Form1_Load does not fire, because it is not connected in your Designer.cs file. Check your form properties!
karlschiffmann's picture


Even when I connect the Form1_Load event (which does fire), I don't get the glControl1_Load firing... I wonder why...

the Fiddler's picture


I should have clarified, the glControl1_Load event works correctly in trunk (SVN revision 2371 or higher). It is broken in the 0.9.9-3 release.

SVN instructions here. If you don't wish to build from source, you can wait for 0.9.9-4 which will come early next week.

syr1111's picture


I'm using 0.9.9-3 and also not seeing the Load event fire, but ONLY when using a non-standard DPI in the operating system. This has been confirmed on separate machines under both Win XP and Vista. The Load event will fire correctly when using the default 96 DPI, but not when using 120 DPI. I don't know if the DPI factor is complicit to the issue itself or just changes timing enough to change the sequence of events, but it does seem very predictable.

I will try this out on 0.9.9-4 when available. For now I am working around it by doing the initialization I want on Load during the first Resize event if Load never fired.

the Fiddler's picture


Thanks for testing, can you please file a new bug report for this issue? I wish to clear all GLControl issues before the 1.0 release and this might get lost here.