简体   繁体   English

c#中Designer.cs文件的作用

[英]Role of Designer.cs File in c#

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.我正在使用 SQLIte 数据库。 Can any one help me in understanding what is the use of the Designer.cs file in a C# project.谁能帮助我理解 C# 项目中Designer.cs文件的用途。

There are lots of kinds of Designer.cs files in a Visual Studio project. Visual Studio 项目中有很多种Designer.cs 文件。 Common ones are:常见的有:

  • Properties\Resources.resx\Resources.Designer.cs file, the auto-generated code from adding resources to the Project + Resources tab Properties\Resources.resx\Resources.Designer.cs文件,将资源添加到Project + Resources选项卡自动生成的代码
  • Properties\Settings.settings\Settings.Designer.cs file, the auto-generated code from adding settings to the Project + Settings tab Properties\Settings.settings\Settings.Designer.cs 文件,将设置添加到 Project + Settings 选项卡时自动生成的代码
  • SomeForm.cs\SomeForm.Designer.cs, the auto-generated code produced by the Winforms designer from the controls you drop on a form SomeForm.cs\SomeForm.Designer.cs,Winforms 设计器根据您放在窗体上的控件自动生成的代码
  • SomeData.xsd\SomeData.Designer.cs, the auto-generated code produced by the dataset designer. 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.您应该从描述中看到模式,您在 Visual Studio 中使用可视化设计器小工具,它生成 C# 代码,在运行时执行一些有用的操作。 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.您 go 通过在解决方案资源管理器 window 中双击其父节点,从 Designer.cs 返回到设计器小工具。永远不要编辑 Designer.cs 文件,当设计器重新生成代码时,您将丢失所有内容。 They are somewhat hidden in the Solution Explorer for that reason.由于这个原因,它们在某种程度上隐藏在解决方案资源管理器中。 If you haven't found them yet: open the nodes to see them.如果您还没有找到它们:打开节点以查看它们。

Designer.cs contains the declaration and initialization of UI controls and layout of form. Designer.cs包含了UI控件的声明和初始化以及窗体的布局。 The form is rendered based on the information provided in designer.cs.表单是根据 designer.cs 中提供的信息呈现的。 This file is autogenerate when a form is created in design mode.在设计模式下创建表单时会自动生成此文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM