tags:

views:

63

answers:

3

Visual Studio creates code similar to this:

namespace MyCustomControls
{
    partial class MyCustomControl
    {
     /// <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 ) )
      {
       components.Dispose ( );
      }
      base.Dispose ( disposing );
     }

     #region Component 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 ( )
     {
      components = new System.ComponentModel.Container ( );
     }

     #endregion
    }
}
+3  A: 

The custom designer file is essential if you are using the designer surface to lay out child controls etc (pretty-much anything in the designer). If you aren't doing then this (for example, you are using custom painting, or adding the child controls manually), then you can usually kill this file pretty safely.

In some ways this makes it easier to implement Dispose() etc.

Marc Gravell
Thanks Marc. You said "In some ways this makes it easier to implement Dispose() etc." You mean killing the file? I see that they have dispose methods there so thought that the file might be needed for proper Dispose of your control.
Joan Venge
A: 

Strictly speaking I don't think so, but then you will lose any design time benefit you would get when creating the control, and my guess is that VS will keep trying to recreate them.

BioBuckyBall
+1  A: 

No, the code which is generated from the initial spit of creating a new custom control is not needed. It doesn't do anything functional and can essentially be commented out of your application.

However, the moment you do anything with your custom control in the designer, very important and useful code will be generated into the designer file. Such as the creation of any added controls, event handler hookup and basic initialization and layout. This code cannot be deleted.

JaredPar
But it has a dispose method. Do you know if that's needed or proper Dispose? I don't call dispose on my controls. I just close the Form.
Joan Venge
Closing the form will call Dispose. **BUT** that dispose is only for the code within that file. The base classes definition of Dispose will do the other important stuff!
tster