简体   繁体   中英

Visual Studio 2017 Designer View not Showing Controls

I am working on a visual c# project with Visual Studio 2017. I added in controls to a custom User Control in the Designer perspective, and after successfully building, this is how it looks.

在此处输入图片说明

At some point, I was undoing (ctrl+z) some mistakes I had made in the class for this UserControl, and now the Designer perspective shows this

在此处输入图片说明

If I build and start the project, I can still see all of my controls in the form that pops up. However, if I make any change in the Designer perspective, it updates the code that was automatically generated, and I lose all the controls I had put in, so the form is now empty.

在此处输入图片说明

How do I get the Designer perspective to show all the controls I had put in? This is important because I still need to add in a few more controls, and I would rather not re-create everything.

EDIT:

Here is the design code that is auto generated

    namespace TypingTestControl
{
    partial class TypingTestControl
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        private string wordsToWrite;
        private char[] stringDelim;
        private char lastKeyPressed;
        private double errorCount;
        private double wordCount;
        private System.Timers.Timer testTimer = null;
        private double elapsedTime;

        /// <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(string wordsToWrite)
        {
            this.wordsToWriteLabel = new System.Windows.Forms.Label();
            this.wordsToWriteValueLabel = new System.Windows.Forms.Label();
            this.userInputTextBox = new System.Windows.Forms.TextBox();
            this.wordsWrittenLabel = new System.Windows.Forms.Label();
            this.timeElapsedLabel = new System.Windows.Forms.Label();
            this.wordsPerMinuteLabel = new System.Windows.Forms.Label();
            this.errorCountLabel = new System.Windows.Forms.Label();
            this.errorsPerWordLabel = new System.Windows.Forms.Label();
            this.timeElapsedValue = new System.Windows.Forms.Label();
            this.wordsWrittenValue = new System.Windows.Forms.Label();
            this.wordsPerMinuteValue = new System.Windows.Forms.Label();
            this.errorCountValue = new System.Windows.Forms.Label();
            this.errorsPerWordValue = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // wordsToWriteLabel
            // 
            this.wordsToWriteLabel.AutoSize = true;
            this.wordsToWriteLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsToWriteLabel.Location = new System.Drawing.Point(3, 4);
            this.wordsToWriteLabel.Name = "wordsToWriteLabel";
            this.wordsToWriteLabel.Size = new System.Drawing.Size(96, 16);
            this.wordsToWriteLabel.TabIndex = 7;
            this.wordsToWriteLabel.Text = "Words to Write";
            // 
            // wordsToWriteValueLabel
            // 
            this.wordsToWriteValueLabel.AutoSize = true;
            this.wordsToWriteValueLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsToWriteValueLabel.Location = new System.Drawing.Point(3, 28);
            this.wordsToWriteValueLabel.Name = "wordsToWriteValueLabel";
            this.wordsToWriteValueLabel.Size = new System.Drawing.Size(77, 16);
            this.wordsToWriteValueLabel.TabIndex = 0;
            this.wordsToWriteValueLabel.Text = "loren ipsum";
            // 
            // userInputTextBox
            // 
            this.userInputTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.userInputTextBox.Location = new System.Drawing.Point(3, 64);
            this.userInputTextBox.Name = "userInputTextBox";
            this.userInputTextBox.Size = new System.Drawing.Size(100, 22);
            this.userInputTextBox.TabIndex = 1;
            // 
            // wordsWrittenLabel
            // 
            this.wordsWrittenLabel.AutoSize = true;
            this.wordsWrittenLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsWrittenLabel.Location = new System.Drawing.Point(489, 4);
            this.wordsWrittenLabel.Name = "wordsWrittenLabel";
            this.wordsWrittenLabel.Size = new System.Drawing.Size(92, 16);
            this.wordsWrittenLabel.TabIndex = 2;
            this.wordsWrittenLabel.Text = "Words Written";
            // 
            // timeElapsedLabel
            // 
            this.timeElapsedLabel.AutoSize = true;
            this.timeElapsedLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.timeElapsedLabel.Location = new System.Drawing.Point(389, 4);
            this.timeElapsedLabel.Name = "timeElapsedLabel";
            this.timeElapsedLabel.Size = new System.Drawing.Size(93, 16);
            this.timeElapsedLabel.TabIndex = 3;
            this.timeElapsedLabel.Text = "Time Elapsed";
            // 
            // wordsPerMinuteLabel
            // 
            this.wordsPerMinuteLabel.AutoSize = true;
            this.wordsPerMinuteLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsPerMinuteLabel.Location = new System.Drawing.Point(593, 4);
            this.wordsPerMinuteLabel.Name = "wordsPerMinuteLabel";
            this.wordsPerMinuteLabel.Size = new System.Drawing.Size(113, 16);
            this.wordsPerMinuteLabel.TabIndex = 4;
            this.wordsPerMinuteLabel.Text = "Words per Minute";
            // 
            // errorCountLabel
            // 
            this.errorCountLabel.AutoSize = true;
            this.errorCountLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.errorCountLabel.Location = new System.Drawing.Point(489, 47);
            this.errorCountLabel.Name = "errorCountLabel";
            this.errorCountLabel.Size = new System.Drawing.Size(74, 16);
            this.errorCountLabel.TabIndex = 5;
            this.errorCountLabel.Text = "Error Count";
            // 
            // errorsPerWordLabel
            // 
            this.errorsPerWordLabel.AutoSize = true;
            this.errorsPerWordLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.errorsPerWordLabel.Location = new System.Drawing.Point(593, 47);
            this.errorsPerWordLabel.Name = "errorsPerWordLabel";
            this.errorsPerWordLabel.Size = new System.Drawing.Size(103, 16);
            this.errorsPerWordLabel.TabIndex = 8;
            this.errorsPerWordLabel.Text = "Errors per Word";
            // 
            // timeElapsedValue
            // 
            this.timeElapsedValue.AutoSize = true;
            this.timeElapsedValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.timeElapsedValue.Location = new System.Drawing.Point(387, 21);
            this.timeElapsedValue.Name = "timeElapsedValue";
            this.timeElapsedValue.Size = new System.Drawing.Size(62, 25);
            this.timeElapsedValue.TabIndex = 8;
            this.timeElapsedValue.Text = "00:00";
            // 
            // wordsWrittenValue
            // 
            this.wordsWrittenValue.AutoSize = true;
            this.wordsWrittenValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsWrittenValue.Location = new System.Drawing.Point(487, 21);
            this.wordsWrittenValue.Name = "wordsWrittenValue";
            this.wordsWrittenValue.Size = new System.Drawing.Size(23, 25);
            this.wordsWrittenValue.TabIndex = 9;
            this.wordsWrittenValue.Text = "0";
            // 
            // wordsPerMinuteValue
            // 
            this.wordsPerMinuteValue.AutoSize = true;
            this.wordsPerMinuteValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.wordsPerMinuteValue.Location = new System.Drawing.Point(591, 21);
            this.wordsPerMinuteValue.Name = "wordsPerMinuteValue";
            this.wordsPerMinuteValue.Size = new System.Drawing.Size(23, 25);
            this.wordsPerMinuteValue.TabIndex = 10;
            this.wordsPerMinuteValue.Text = "0";
            // 
            // errorCountValue
            // 
            this.errorCountValue.AutoSize = true;
            this.errorCountValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.errorCountValue.Location = new System.Drawing.Point(487, 64);
            this.errorCountValue.Name = "errorCountValue";
            this.errorCountValue.Size = new System.Drawing.Size(23, 25);
            this.errorCountValue.TabIndex = 11;
            this.errorCountValue.Text = "0";
            // 
            // errorsPerWordValue
            // 
            this.errorsPerWordValue.AutoSize = true;
            this.errorsPerWordValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.errorsPerWordValue.Location = new System.Drawing.Point(591, 64);
            this.errorsPerWordValue.Name = "errorsPerWordValue";
            this.errorsPerWordValue.Size = new System.Drawing.Size(50, 25);
            this.errorsPerWordValue.TabIndex = 12;
            this.errorsPerWordValue.Text = "0.00";
            // 
            // TypingTestControl
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.errorsPerWordValue);
            this.Controls.Add(this.errorCountValue);
            this.Controls.Add(this.wordsPerMinuteValue);
            this.Controls.Add(this.wordsWrittenValue);
            this.Controls.Add(this.timeElapsedValue);
            this.Controls.Add(this.errorsPerWordLabel);
            this.Controls.Add(this.errorCountLabel);
            this.Controls.Add(this.wordsPerMinuteLabel);
            this.Controls.Add(this.timeElapsedLabel);
            this.Controls.Add(this.wordsWrittenLabel);
            this.Controls.Add(this.userInputTextBox);
            this.Controls.Add(this.wordsToWriteValueLabel);
            this.Controls.Add(this.wordsToWriteLabel);
            this.Name = "TypingTestControl";
            this.Size = new System.Drawing.Size(715, 95);
            this.Load += new System.EventHandler(this.TypingTestControl_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label wordsToWriteLabel;
        private System.Windows.Forms.Label wordsToWriteValueLabel;
        private System.Windows.Forms.TextBox userInputTextBox;
        private System.Windows.Forms.Label wordsWrittenLabel;
        private System.Windows.Forms.Label timeElapsedLabel;
        private System.Windows.Forms.Label wordsPerMinuteLabel;
        private System.Windows.Forms.Label errorCountLabel;
        private System.Windows.Forms.Label errorsPerWordLabel;
        private System.Windows.Forms.Label timeElapsedValue;
        private System.Windows.Forms.Label wordsWrittenValue;
        private System.Windows.Forms.Label wordsPerMinuteValue;
        private System.Windows.Forms.Label errorCountValue;
        private System.Windows.Forms.Label errorsPerWordValue;
    }
}

Everything in the InitializeComponent method gets reset if I update the Designer perspective in any way, even if I just resize the form.

I've had problem with Usercontrols too, my controls wouldn't show.

The reason was I did put some code in the Sub() function of the Usercontrol that was being executed while in Design mode (even without running the program!)

The piece of code crashed the designer, preventing me to see any control

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM