无法在 vb.net 中查看表单设计器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6458667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:34:38  来源:igfitidea点击:

Can not view the form designer in vb.net

vb.net

提问by Summer

I use MS visual studio 2010. I did open designer and view the form for the same file A before. But after some small changes, I can no longer view the form designer.vb, but can only view code in designer.vb. Even if I go back to the original source, I still can not open designer!!

我使用 MS Visual Studio 2010。我之前打开过设计器并查看了同一个文件 A 的表单。但是经过一些小改动后,我再也无法查看表单designer.vb,只能查看designer.vb中的代码了。就算我回到原来的源头,我还是打不开设计师!!

The error is: The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following clsses in the file A-The base class BaseClass could not be loaded. Ensure the assembly has been referenced and all that projects have been built.

错误是:无法为此文件显示设计器,因为无法设计其中的任何类。设计者检查了文件A中的以下类-无法加载基类BaseClass。确保已引用程序集并已构建所有项目。

I checked that the file A inherits from the BaseClass. The BaseClass has a simple form and can be viewed by designer. I have a successful build. Actually, I can run the program correctly. I even tried delete bin and objects then build, but nothing helps.

我检查了文件 A 是否继承自 BaseClass。BaseClass 具有简单的形式,可供设计者查看。我有一个成功的构建。实际上,我可以正确运行程序。我什至尝试删除 bin 和对象然后构建,但没有任何帮助。

I have many files that can not be opened in designer.vb. This is killing me! How can I make changes to the form then? Directly write code to designer.vb? But many suggest that do not write code directly in designer.vb

我有很多无法在designer.vb 中打开的文件。这要死我了!那我该如何更改表格呢?直接写代码到designer.vb?但是很多人建议不要直接在designer.vb中写代码

回答by Hans Passant

Use Project + Add Class to add classes to your project, don't put them in the form's source code file. If you have to then add them to the bottom or nested inside the form class, don't put them ahead of the form class declaration. The form class must be first.

使用 Project + Add Class 将类添加到您的项目中,不要将它们放在表单的源代码文件中。如果您必须将它们添加到底部或嵌套在表单类中,请不要将它们放在表单类声明之前。表单类必须是第一个。

回答by Falah

I got the same problem, to solve it, run the program with this command to clear all of the options to skip loading added to VSPackages:

我遇到了同样的问题,要解决它,请使用此命令运行程序以清除添加到 VSPackages 的所有跳过加载选项:

"C:\Program Files\Microsoft Visual Studio 8.0\Common7\IDE\devenv.exe" /ResetSkipPkgs

回答by navule

Click on "Show All Files" Icon at the top of the Solution Explorer, you will see the Designer.vb file

单击解决方案资源管理器顶部的“显示所有文件”图标,您将看到 Designer.vb 文件

回答by user5748747

While you are on the form code, click on View > Designer, and it will showup.

当您在表单代码上时,单击“视图”>“设计器”,它将显示出来。

回答by user191880

In my case, the problem came about when I put the form into a namespace and then took it out. The FrmXYZ.vb lost its proper build information in the project file. To fix it, I right clicked on the project in the Solution Explorer, selected "unload", and then, "edit". I searched for my form by name. First, I found a compile section about FrmXYZ.Designer.vb. This looks like the following:

就我而言,当我将表单放入命名空间然后将其取出时,问题就出现了。FrmXYZ.vb 在项目文件中丢失了正确的生成信息。为了修复它,我在解决方案资源管理器中右键单击该项目,选择“卸载”,然后选择“编辑”。我按名称搜索了我的表格。首先,我找到了一个关于 FrmXYZ.Designer.vb 的编译部分。如下所示:

<Compile Include="Forms\FrmXYZ.Designer.vb">
   <DependentUpon>FrmXYZ.vb</DependentUpon>
</Compile>

This was all good. Then next section was for the form file, FrmXYZ.vb. This was my problem. It read,

这一切都很好。然后下一部分是表单文件,FrmXYZ.vb。这是我的问题。它读到,

<Compile Include="Forms\FrmXYZ.vb" />

I changed it to the following to make visual studio know it was a form:

我将其更改为以下内容以使 Visual Studio 知道它是一种形式:

<Compile Include="Forms\FrmXYZ.vb">
  <SubType>Form</SubType>
</Compile>

Then I saved the file, closed the file, right clicked on the project, and selected, "reload project".

然后我保存文件,关闭文件,右键单击项目,然后选择“重新加载项目”。

Problem solved (for me).

问题解决了(对我来说)。

回答by Dan Posey

I too had a situation in which I had xxx.Designer.vb, xxx.resx, and xxx.vb showing in the Solution for my Project. To fix this, I backed up my Solution/Project (Very Very Important), then I deleted the 3 xxx files found in my Solution Explorer for my Project. I then selected and copied the 3 xxx files from my backup and pasted them using Windows Explorer into the folder for my project. (make sure the folder you paste to is the folder shown in your Solution. After the paste I went back into the Project, then to the folder where the original xxx files where located, right clicked on that folder and clicked on Add - Existing Item. Then clicked ONLY on the xxx.vb file. Fixed. Hope this works for you.

我也遇到过在我的项目的解决方案中显示 xxx.Designer.vb、xxx.resx 和 xxx.vb 的情况。为了解决这个问题,我备份了我的解决方案/项目(非常非常重要),然后我删除了在我的项目的解决方案资源管理器中找到的 3 个 xxx 文件。然后我从备份中选择并复制了 3 个 xxx 文件,并使用 Windows 资源管理器将它们粘贴到我的项目文件夹中。(确保您粘贴到的文件夹是您的解决方案中显示的文件夹。粘贴后我回到项目,然后到原始 xxx 文件所在的文件夹,右键单击该文件夹并单击添加 - 现有项目. 然后只点击 xxx.vb 文件. 修复. 希望这对你有用.

回答by user2327795

You can also try doing this:

您也可以尝试这样做:

  • Close all the UI design pages
  • Clean Solution
  • Build Solution
  • Open the desired UI design pages
  • 关闭所有 UI 设计页面
  • 清洁溶液
  • 构建解决方案
  • 打开所需的 UI 设计页面

This might or might not help but it certainly resolved the same issue in my project.

这可能有帮助,也可能无济于事,但它肯定解决了我项目中的相同问题。

回答by Nawaz Awan

if you no can view the design but only the code, then close VS go to your project directory, find the form in there, open it in any text editor and add the class name as public at the top for example

如果您不能查看设计而只能查看代码,则关闭 VS 转到您的项目目录,在其中找到表单,在任何文本编辑器中打开它并在顶部添加类名作为公共

Public Class FrmSettings

End Class

that's it, now you can view the form in VS design

就是这样,现在你可以在VS design中查看表单了

回答by Antonio Delrio

I had this same problem, although my problem was because I obfuscated my project file. After deobfuscation, and rebuilding, it seemed to work.

我有同样的问题,虽然我的问题是因为我混淆了我的项目文件。经过去混淆和重建后,它似乎起作用了。

回答by Summer

I finally can view form in designer by doing this:

我终于可以通过这样做在设计器中查看表单:

In my form_designer.vb,

在我的 form_designer.vb 中,

Exsiting code:

现有代码:

Inherits Base_Class 'Base_Class is defined in my project

Inherits Base_Class 'Base_Class 在我的项目中定义

Change to:

改成:

Inherits Form 'Form is defined by windows

Inherits Form '窗体由窗口定义

Then I can view form in designer!!!

然后我可以在设计器中查看表单!!!

Of course, I can not build files successfully since the inheritence is not correct. But I can first edit in form_designer, and then change back to 'Inherits Base_Class' and build or compile

当然,由于继承不正确,我无法成功构建文件。但是我可以先在form_designer中编辑,然后改回'Inherits Base_Class'并构建或编译