Microsoft KB Archive/836669

= Code comments that you add in the InitializeComponent method are lost when you add a control in Visual Studio .NET or in Visual Studio 2005 =

Article ID: 836669

Article Last Modified on 11/27/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-





SYMPTOMS
In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, when you create a Microsoft Windows Application project, you can add code comments in the InitializeComponent method. However, if you add a control to the Windows Form later, the code comments that you added previously are lost.



CAUSE
When you add a control to the Windows Form, the Windows Forms Designer automatically regenerates the code for the InitializeComponent method. Therefore, the code comments that you added are lost.



MORE INFORMATION
The code that the Windows Forms Designer automatically generates contains comments that appear before the InitializeComponent method. These comments state that you must not use the code editor to modify the contents of the InitializeComponent method.

The following automatically generated code comments appear before the InitializeComponent method in Windows Form class files:   Visual C# .NET or Visual C# 2005 /// Required method for Designer support - do not modify

/// the contents of this method with the code editor.   Visual Basic .NET or Visual Basic 2005 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Note In these code comments, &quot;Windows Form Designer&quot; is a misspelling of &quot;Windows Forms Designer.&quot; 

Steps to reproduce the behavior

 * 1) Start Visual Studio .NET or Visual Studio 2005.
 * 2) Create a Windows Application project that is named MyApplication. By default, a Windows Form that is named Form1 is created.
 * 3) Add a Button control to the Form1 form.
 * 4) Add some code comments in the InitializeComponent method of the Form1 class file.
 * 5) Click the Form1[Design] tab.
 * 6) Add a Label control to the Form1 form.
 * 7) Switch to the code view of the Form1 form.

Notice that your code comments have been lost.

