Designer.cs文件在c#中的作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10101073/
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-08-09 12:25:39  来源:igfitidea点击:

Role of Designer.cs File in c#

c#visual-studio

提问by Jainendra

I am getting Designer.cs file in my project and the comment in the file says it is being generated by an automatic tool.

我在我的项目中获取 Designer.cs 文件,文件中的注释说它是由自动工具生成的。

This was an existing project so I don't know much about that. It is generated for one schema.cs which consists of schemas of all the tables in Database.

这是一个现有的项目,所以我对此知之甚少。它是为一个由数据库中所有表的模式组成的 schema.cs 生成的。

I am using a SQLIte DB. Can any one help me in understanding what is the use of the Designer.csfile in a C# project.

我正在使用 SQLIte 数据库。任何人都可以帮助我了解该Designer.cs文件在 C# 项目中的用途。

采纳答案by Hans Passant

There are lots of kindsof Designer.cs files in a Visual Studio project. Common ones are:

有许多在Visual Studio项目的Designer.cs文件。常见的有:

  • Properties\Resources.resx\Resources.Designer.cs file, the auto-generated code from adding resources to the Project + Resources tab
  • Properties\Settings.settings\Settings.Designer.cs file, the auto-generated code from adding settings to the Project + Settings tab
  • SomeForm.cs\SomeForm.Designer.cs, the auto-generated code produced by the Winforms designer from the controls you drop on a form
  • SomeData.xsd\SomeData.Designer.cs, the auto-generated code produced by the dataset designer.
  • Properties\Resources.resx\Resources.Designer.cs 文件,将资源添加到 Project + Resources 选项卡时自动生成的代码
  • Properties\Settings.settings\Settings.Designer.cs 文件,将设置添加到 Project + Settings 选项卡时自动生成的代码
  • SomeForm.cs\SomeForm.Designer.cs,由 Winforms 设计器根据您放置在表单上的控件自动生成的代码
  • SomeData.xsd\SomeData.Designer.cs,数据集设计器生成的自动生成的代码。

Given that you name a database in your question it is somewhat likely that you are talking about the last one. You ought to see the pattern from the descriptions, you use a visual designer gadget in Visual Studio and it produces C# code that does something useful at runtime. You go back from the Designer.cs to the designer gadget by double-clicking its parent node in the Solution Explorer window. Don't ever edit the Designer.cs file, you'll lose everything when the designer re-generates the code. They are somewhat hidden in the Solution Explorer for that reason. If you haven't found them yet: open the nodes to see them.

鉴于您在问题中命名了一个数据库,您很可能在谈论最后一个。您应该从描述中看到模式,您在 Visual Studio 中使用了可视化设计器小工具,它会生成 C# 代码,在运行时执行一些有用的操作。通过在解决方案资源管理器窗口中双击它的父节点,您可以从 Designer.cs 返回到设计器小工具。永远不要编辑 Designer.cs 文件,当设计器重新生成代码时,您将丢失所有内容。出于这个原因,它们在解决方案资源管理器中有些隐藏。如果您还没有找到它们:打开节点查看它们。

回答by Ram

Designer.cs contains the declaration and initialization of UI controls and layout of form. The form is rendered based on the information provided in designer.cs. This file is autogenerate when a form is created in design mode.

Designer.cs 包含 UI 控件和表单布局的声明和初始化。该表单是根据designer.cs 中提供的信息呈现的。在设计模式下创建表单时,此文件会自动生成。