文件损坏?

发布于 2024-08-03 23:42:55 字数 369 浏览 2 评论 0原文

我有一个表单 MainForm,直到今天早上它都工作得很好。我对不同的表单进行了一些代码修改,当我运行该应用程序时,我在 MainForm 中收到了一个错误(错误无关紧要)。

我进入 MainForm 看看问题出在哪里,我对所看到的感到震惊......我所有的控件都消失了。起初我很惊慌,但当我进入 MainForm.Designer.cs 文件并看到控件的所有代码仍然存在时,我有了一点希望。

因此,设计器文件看起来不错,但设计视图不显示任何控件。

以前有人发生过这种情况吗?我的文件损坏了吗?我能做些什么来解决这个问题吗?

我确实有一个备份,但除非绝对必要,否则我不想使用它,因为它已经是一天前的了,而且我不想重做我最近的工作。

谢谢...

I have a form, MainForm, which was working just fine and dandy until earlier this morning. I made some code modifications to a different form and when I went to run the application, I received an error in MainForm (error is irrelevant).

I went into MainForm to see what the problem was and was horrified at what I saw... ALL MY CONTROLS WERE GONE. At first I panicked, but then had a bit of hope when I went into the MainForm.Designer.cs file and saw that all the code for the controls was still there.

So, the Designer file seems fine and yet the design view does not display any of the controls.

Has this ever happened to anyone before? Is my file corrupt? Is there anything I can do to fix this?

I do have a backup, but would prefer not to use it unless absolutely necessary as it is a day old and I do not want to redo my most recent work.

Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

等你爱我 2024-08-10 23:42:55

查看此页面,列出一些原因可能发生的情况、预防方法以及恢复方法。

Take a look at this page, listing some reasons why this might have happened, ways to prevent it, and how to recover.

等数载,海棠开 2024-08-10 23:42:55

尝试以下步骤:

  • 关闭所有源代码窗口。
  • 进行全部清理。
  • 退出 DevStudio。
  • 启动 DevStudio。
  • 打开您的解决方案(如果它没有自动加载)
  • 构建您的解决方案。
  • 在设计器中打开面板。

Try these steps:

  • Close all source code windows.
  • Do a Clean All.
  • Exit DevStudio.
  • Start DevStudio.
  • Open your solution (if it doesn't auto-load)
  • Build your solution.
  • Open your panel in the designer.
鸢与 2024-08-10 23:42:55

我遇到了同样的问题...我打开了 Designer.cs 文件,发现我的主窗体代码比以前的备份短了很多。

我将备份中的代码(10 天前...)复制到我的程序中,并在几分钟内恢复了大部分功能。又过了 5 分钟,我又回到了发生错误之前的位置。

然后我备份了所有内容 - 向代码之神点燃一支蜡烛,并祈祷 - “今天给我们健康的代码......”我希望他正在倾听。

I had the same issue... I opened up the designer.cs file and found that my Main Form code was quite a bit shorter than on a previous backup.

I copied the code from the backup (10 days old...) into my program, and I recovered most of my functionality in minutes. Another 5 minutes, and I was where I was before the error.

I then backed up everything - lit a candle to the God of Code, and prayed - "give us this day our healthy code..." I hope he is listening.

撩动你心 2024-08-10 23:42:55

你会想看看你做了什么。确保文件名全面匹配,并且您不会意外地重命名任何单个文件。

还要确保 3 个文件之间的类名全面匹配。

You will want to take a look at what you did. Make sure file names match across the board, and that you didn't manage to accidentally re-name any of the individual files.

Also make sure that class names match across the board, between the 3 files.

书间行客 2024-08-10 23:42:55

过去,重新启动 Visual Studio 在很多情况下都对我有用。确保关闭所有副本并检查任务管理器中正在运行的进程列表,以确保没有任何您不知道的副本正在运行。重新启动并不是在所有情况下都有帮助(如果你确实有一个损坏的文件),但它对我来说很多时候都有效。

Restarting Visual Studio has worked in a lot of cases for me in the past. Make sure you close all copies and check the list of running processes in Task Manager to make sure there aren't any copies running you don't know about. Restarting won't help in every case (if you really have a corrupted file) but it works a lot of the time for me.

-小熊_ 2024-08-10 23:42:55

上次我看到这一点时,我没有将我的部分类 Form 作为代码隐藏中的第一件事。

namespace WinForms{
   public partial class MyForm : Form{
   }
}

就像

namespace WinForms{
    public class SomeClass{
       //some code..
    }

    public partial class MyForm : Form { } 
}

The last time I saw that, I did not have my my partial class Form as the first thing in the codebehind.

namespace WinForms{
   public partial class MyForm : Form{
   }
}

was like

namespace WinForms{
    public class SomeClass{
       //some code..
    }

    public partial class MyForm : Form { } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文