Windows Forms设计器调整UI时出现"Should have two or more class parts"错误
Windows Forms设计器报错"Should have two or more class parts.",无法保存UI更改
- 从昨日起,使用Windows Forms设计器调整既有应用UI时,会收到错误提示:
Should have two or more class parts. - 新建仅包含单个按钮的WinForms测试应用,代码编辑、程序运行及调试均正常,但只要调整按钮或Form1窗口大小并尝试重建应用,就会触发该错误且无额外信息,Form1.Designer.cs不会保存UI调整的更改;关闭Visual Studio时需放弃更改,重新打开后应用可正常运行,但再次调整UI仍会报错
- 尝试创建极简C#新项目,问题同样出现
- 注意到昨日Visual Studio进行了补丁更新,怀疑与此问题相关,执行
devenv /Safemode后仍无法解决 - 直接手动编辑Designer.cs文件修改button1的BackColor和Form1的尺寸,保存运行一切正常,推测问题出在Windows Forms设计器本身
注:本想添加"net7.0-windows"标签,但因声望不足且该标签尚未创建无法添加。
private void InitializeComponent() { button1 = new Button(); SuspendLayout(); // // button1 // button1.Location = new Point(28, 18); button1.Name = "button1"; button1.Size = new Size(314, 105); button1.TabIndex = 0; button1.Text = "Calculate Tables"; button1.BackColor = System.Drawing.Color.Orange; //button1.UseVisualStyleBackColor = true; button1.Click += button1_Click; // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(400, 200); Controls.Add(button1); Name = "Form1"; Text = "Form1"; ResumeLayout(false); }
内容的提问来源于stack exchange,提问作者user1217123
相关产品推荐
相关产品推荐

