Windows Forms Designer Problem When Renaming New Form Before Adding Controls

Nicholas Piazza 541 Reputation points
2022-09-14T20:22:54.647+00:00

Note: I have reported the problem below in Visual Studio 2022 Feedback. Just wanted to see if any of you have a suggestion.

Normally, when you create a new Form in Windows Forms and add controls to the form, the Designer automatically fills in the Designer.cs file with information about those controls, properties set, etc. However, If you create a new form and before adding controls you rename the form from its default name of Form (Form.cs, etc.) when you add controls and set properties for those controls in the form the Designer does not update the new form Designer.cs file. Then when you build and run the application, the displayed form is empty; none of the controls that were added using the Designer appear there because the Designer.cs file didn’t record the information. This is very frustrating. At this point, one either has to delete the form and start over, adding controls to the default Form.cs file and only afterwards renaming it, or creating a new InitializeComponent method from scratch doing all the work yourself. I would like the VS Designer to be smart enough to know that if the form is renamed before adding controls that the Designer.cs file should still be filled in correctly when controls are added to the form. Shown below is the minimal Designer.cs file for a form that was renamed to ConvertLength.
namespace MathHelper
{
partial class ConvertLength
{
/// <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 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.components = new System.ComponentModel.Container ();  
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
        this.ClientSize = new System.Drawing.Size (800, 450);  
        this.Text = "DialogLength";  
    }  

    #endregion  
}  

}

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,914 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,309 questions
{count} vote

11 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.