c# - 由于奇怪的错误,无法在 Visual Studio 2008 C# Windows 窗体中看到设计器 View

标签 c# .net visual-studio winforms visual-studio-2008

当我尝试单击设计器选项卡以获取设计器 View 时,出现此错误:

To prevent possible data loss before loading the designer, the following errors must be resolved:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Form1 --- The base class 'System.Windows.Forms.Form' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

我想进入设计师,但不知道出了什么问题。我的 Form1 代码在顶部如下所示:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Diagnostics;

    namespace foobar
    {
        public partial class Form1 : Form
        {

        List<CharLabel> allChars = new List<CharLabel>();

        public Form1()
        {
... etc ...

有什么想法吗?

最佳答案

当您直接从代码编辑器更改分部类(如表单)内的命名空间或其他项目时,您正在邀请疯狂。顾名思义,分部类是在代码 View 上“部分”定义的类,但还有另一部分由 VS 自动生成,即该类的另一部分。在该部分中,它包含所有 UI 元素、字体、默认值等的定义。当您更改类的一部分中的 namespace 时,另一部分不知道要做什么,然后就会出现有趣的错误。当更改命名空间、类名、事件方法名时,始终使用 VS 中的 Refactor 选项。

在你的情况下,我可能会回到它的旧名称,然后使用VS提供的重构选项(突出显示组件名称,Ricgh单击,重构->重命名)

希望这有帮助。

关于c# - 由于奇怪的错误,无法在 Visual Studio 2008 C# Windows 窗体中看到设计器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1180891/

相关文章:

c# - 将 XmlNode 添加到 XmlWriter 中

c# - XML反序列化 'standardising'行尾,如何停止? (。网)

c# - 如何检查 LinqToSql DataContext 运行了多少查询?

vb.net - 从错误对象获取错误的位置

c++ - 如何将png资源加载到对话框上的图片控件中?

c# - 如果在列表框中选择索引,则将列表框与数据库链接并在文本框中显示值。 C#

c# - 在.NET Core中使用SHA-1

c# - 如何将图片保存到数据库中?

c# - 从 FileStream 获取字节数组的正确方法是什么?

visual-studio - 门控 checkin : Sheving the Sources causes rollback in Visual Studio