我正在使用Visual Studio 2017进行可视c#项目。我在Designer透视图中将控件添加到自定义用户控件中,并且在成功构建后,外观就是这样。
在某个时候,我正在撤消(ctrl + z)我在该UserControl类中犯的一些错误,现在Designer透视图显示了这一点
如果我构建并启动项目,仍然可以在弹出的窗体中看到所有控件。但是,如果我在Designer透视图中进行了任何更改,它将更新自动生成的代码,并且我将丢失所有已放入的控件,因此该表单现在为空。
如何获得Designer透视图以显示我已放入的所有控件?这很重要,因为我仍然需要添加一些控件,并且我不想重新创建所有内容。
编辑:
这是自动生成的设计代码
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;
}
}
如果我以任何方式更新Designer透视图,即使我只是调整窗体的大小,InitializeComponent方法中的所有内容都会重置。
答案 0 :(得分:0)
我也遇到了Usercontrols的问题,我的控件无法显示。
原因是我确实将一些代码放入了在设计模式下正在执行的Usercontrol的Sub()函数中(即使没有运行该程序!)
这段代码使设计人员崩溃,使我无法看到任何控件