I recently discovered isupportinitialize this interface. It is useful when developing a WinForm control that is more complex.
There's an introduction to ISupportInitialize on MSDN, and I'm just going to talk about under what circumstances it works.
Problem
I want to make a more complex control "Openglcontrol", it can execute OpenGL command in WinForm program, Render 3D scene. This control has some associated properties, which are written (automatically generated) in the designer:
//OpenGLControl1
//
This.openGLControl1.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.openGLControl1.BitDepth =;
This.openGLControl1.DrawRenderTime = true;
This.openGLControl1.FrameRate = 29.41176F;
This.openGLControl1.Location = new System.Drawing.Point (a);
This.openGLControl1.Name = "OpenGLControl1";
This.openGLControl1.RenderContextType = SharpGL.RenderContextType.NativeWindow;
This.openGLControl1.Size = new System.Drawing.Size (768, 379);
This.openGLControl1.TabIndex = 0;
This.openGLControl1.OpenGLDraw + = new System.Windows.Forms.PaintEventHandler (This.openglcontrol1_opengldraw);
So the question came.
Bitdepth,opengldraw,framerate and so on must be set before size this property. How do we control this? This auto-generated code knows how we're going to take care of it.
So the ISupportInitialize interface appeared. If Openglcontrol implements this interface, then the code generated automatically in the designer will be:
private void InitializeComponent ()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager (typeof (FormExample1));
This.label1 = new System.Windows.Forms.Label ();
This.linklabel1 = new System.Windows.Forms.LinkLabel ();
This.openglcontrol1 = new Sharpgl.openglcontrol ();
((System.ComponentModel.ISupportInitialize) (this.openglcontrol1)). BeginInit ();
This. SuspendLayout ();
// ... ordianry designer code ...
(
(System.ComponentModel.ISupportInitialize) (this.openglcontrol1)). EndInit ();
This. ResumeLayout (false);
This. PerformLayout ();
}
All right. Want the Size property to be set last, well, let's just say it's in the EndInit method.