C# 当我尝试用C执行Windows窗体时,它是空的?
当我尝试执行windows窗体应用程序时,我看到的是一个完全白色的空白窗体。当我查看我的form1.cs[设计]时,一切看起来都正常,但当我运行它时却不正常?我看不到标签、按钮或任何东西。我以前从未遇到过这个问题,我的InitializeComponent应该在哪里?这是我的Form1.Designer.Cs,或者我的Form1.Cs有问题C# 当我尝试用C执行Windows窗体时,它是空的?,c#,windows,forms,winforms,C#,Windows,Forms,Winforms,当我尝试执行windows窗体应用程序时,我看到的是一个完全白色的空白窗体。当我查看我的form1.cs[设计]时,一切看起来都正常,但当我运行它时却不正常?我看不到标签、按钮或任何东西。我以前从未遇到过这个问题,我的InitializeComponent应该在哪里?这是我的Form1.Designer.Cs,或者我的Form1.Cs有问题 partial class Identity { /// <summary> /// Required
partial class Identity
{
/// <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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(278, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(116, 87);
this.label1.TabIndex = 0;
this.label1.Text = "VÄLKOMMEN!";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(67, 87);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(222, 23);
this.label2.TabIndex = 1;
this.label2.Text = "Skriv in ditt namn och personnummer nedan.:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(67, 181);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(51, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Förnamn:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(63, 217);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(58, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Efternamn:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(30, 269);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(161, 13);
this.label5.TabIndex = 4;
this.label5.Text = "Personummer:(ååååmmdd - xxxx)";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(127, 174);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 5;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(127, 210);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 6;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(197, 266);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(164, 20);
this.textBox3.TabIndex = 7;
//
// button1
//
this.button1.Location = new System.Drawing.Point(307, 329);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(87, 51);
this.button1.TabIndex = 8;
this.button1.Text = "Kör!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(337, 395);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(35, 13);
this.label6.TabIndex = 9;
this.label6.Text = "label6";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(33, 423);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(492, 296);
this.richTextBox1.TabIndex = 10;
this.richTextBox1.Text = "\"\"";
//
// button2
//
this.button2.Location = new System.Drawing.Point(662, 650);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(116, 69);
this.button2.TabIndex = 11;
this.button2.Text = "Avsluta:";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Identity
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1207, 755);
this.Controls.Add(this.button2);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label6);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Identity";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button2;
private EventHandler label1_Click;
}
}
根据注释线索,您创建了一个新的解决方案,从有问题的表单的设计器代码复制了一些select行,注释掉了设计器代码中缺少的一些事件处理程序,然后能够加载设计器并添加缺少的事件处理程序及其主体代码。生成的表单工作正常Form1.cs中的Form1在其构造函数中调用InitializeComponent吗?@Steve我想是的,自从我启动这个新程序以来,我还没有真正移动过它,我在Google上研究过这个问题,并看到了解决方案,但没有任何东西比普通的更突出,我想,我是一个初学者,所以可能错过了一些东西。我可以在注释中粘贴我的构造函数吗?要显示它的外观,请不要显示form1.cs的全部,而只显示该部分的开头;在form.designer文件中的字段声明中?你有没有以其他方式篡改过这个文件?吉米没有,我没有做任何不寻常的事情,即使我把它删除了,它仍然是空白的。我以前从未遇到过这个问题。我建议你开始一个新项目,制作一个名为Identity的新表单,从这篇文章中复制除最后3行之外的每一行代码,并将其粘贴到新Identity.Designer.cs(除最后2行外)的每一行顶部,从而省去private EventHandler label1\u Click;正如Jimi所指出的,这是出乎意料的,然后复制你的结构和两个按钮点击处理程序,双击每个按钮,粘贴代码等等——重新启动这个表单,你可能会比反复敲打任何有问题的表单更快地启动和运行。
public partial class Identity : Form
{
public Identity()
{
InitializeComponent();
}
public struct Person
{
public double idok;
public string fname;
public string lname;
public string id;
public string sex;
public string year;
public string fyear;
}