The usefulness of the ISupportInitialize interface

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.