在C#更改Windows自动生成的代码窗体应用程序项目 [英] Changing autogenerated code in a C# Windows Forms Application project

查看:738
本文介绍了在C#更改Windows自动生成的代码窗体应用程序项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你打开一个新的C#Windows窗体应用程序项目在Visual Studio 2008中,你得到了很多的自动生成的代码(AssemblyInfo.cs中,Resources.Designer.cs,Settings.Designer.cs,Form1.Designer.cs,Form1上。 RESX,Program.cs中)。

When you open a new C# Windows Forms Application project in Visual Studio 2008, you get a lot of autogenerated code (AssemblyInfo.cs, Resources.Designer.cs, Settings.Designer.cs, Form1.Designer.cs, Form1.resx, Program.cs).

除了增加从工具箱Form1.cs的[设计]与代码组件Form1.cs中,你能不能改变什么文件?如何?而应交由哪些文件,因为它们是

Beside adding components from the Toolbox to Form1.cs[Design] and code to Form1.cs, what files can you change? And how? And what files should be left as they are?

PS:这是一个庞大的问题,据我可以告诉。我不指望一个详尽的答案。你愿意分享的所有信息就行了。我也想提一提,我是C#初学者,只想要最基本的信息

PS: This is a vast subject, as far as I can tell. I don't expect an exhaustive answer. Any information you care to share will do. I also want to mention that I'm a C# beginner and only want the most basic information.

PPS:如果你想回答搜索互联网或者类似的东西,不要。我已经在网上搜索,并会如此做一遍又一遍,直到我发现我要找的答案。我发现一些有用的信息,但我觉得我需要更多。我认为这是可能的,我会得到,在stackoverflow.com

PPS: In case you're thinking about answering "Search the internet" or something like that, don't. I have searched the internet and will do so again and again until I find the answers I'm looking for. I have found some useful information, but I feel I need more. I think it's likely I will get that at stackoverflow.com.

更​​新1:这个问题已经有了答案。我标志着sh_kamalh答案为接受。我想所接受,以及为纪念大卫和汉斯帕桑特答案,但我不认为你可以标记一个以上的答案为接受的。或者,你能吗?

Update 1: This question has been answered. I've marked the answer from sh_kamalh as accepted. I would like to mark the answers from David and Hans Passant as accepted as well, but I don't think you can mark more than one answer as the accepted one. Or can you?

从我可以从答案dedcue,你应该永远不会改变自动生成的代码,在C#Windows窗体应用程序项目在Visual Studio 2008中我不不懂一切的答案,虽然,可能忽略了一些东西。

From what I can dedcue from the answers, you should never change the autogenerated code in a C# Windows Forms Application project in Visual Studio 2008. I don't understand everything in the answers, though, and may have overlooked something.

如果你不与总结右的上方或下方的答案同意,随意添加一个矛盾的答案。或者,如果你有以下的补充答案的答案,随意添加这个问题的答案。我敢肯定有更多的要在这个问题说

If you don't agree with the summary right above or the answers below, feel free to add a contradictory answer. Or if you have an answer that supplement the answers below, feel free to add that answer. I'm sure there's more to be said on this subject.

更​​新2:看来你也可以写你自己一个C#版本的Windows窗体应用程序项目(见下文戴维斯回答,我忘了,当我写了更新1)。它似乎也应从如果你从头开始。

Update 2: It seems you can also write your own version of a C# Windows Forms Application project (see Davids answer below, which I forgot about when I wrote "Update 1"). It also seems you should start from scratch if you do.

推荐答案

为什么要更改自动生成的文件?< BR>
在形式的情况下,你不应该改变了.Designer.cs或.resx文件,因为它们会生成每次你改变所以无论改变你将被覆盖的代码再生下一次的形式。

。如果你想改变在Designer.cs东西,你可以做原来的CS文件的变化,因为该类被标记为局部的,这意味着从文件Form1.cs和Form1.designer.cs代码如果你想添加你的资源添加一个资源文件,并保留生成的.resx文件的完整结合起来,以产生最终代码。结果

。对于AssemblyInfo.cs中,您可以更改组件的一般信息。

Why do you want to change the auto-generated files?
In case of forms you should not change .Designer.cs or the .resx files because they will be generated everytime you change the form so whatever changes you do will be overwritten next time the code is regenerated.
If you want to change something in Designer.cs, you can do that change in the original cs file because the class is marked as partial which means that the code from the files Form1.cs and Form1.Designer.cs is combined to generate the final code.
If you want to add your resources add a resource file and leave the generated .resx file intact. For AssemblyInfo.cs you can change the general information of the assembly.

长话短说见好就收生成的文件完好无损。

Long story short just leave the generated files intact.

这篇关于在C#更改Windows自动生成的代码窗体应用程序项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆