建议触摸 Designer.cs 文件中的代码吗?
我是否建议我触摸 Windows 窗体应用程序的 Designer.cs 文件?当我将标签引用到我的设置文件时,我计划以这样的方式对其进行编码:如果我的设置文件显示了
int startup = 0;
我的组合框选择的代码处理程序,它将
if (settingObject.bootOnStartup == 0)
{
comboStartup.SelectedIndex = 0;
}
else
{
comboStartup.SelectedIndex = 1;
}
对其功能起作用,但它会导致设计窗口崩溃。
Is it advisable for me to touch the designer.cs file for my windows form application? As I am referencing the labels to my settings file, I plan to code it in such a way that if my settings file shows
int startup = 0;
the code handler for my combo box selection would be
if (settingObject.bootOnStartup == 0)
{
comboStartup.SelectedIndex = 0;
}
else
{
comboStartup.SelectedIndex = 1;
}
it does works for its function but it sort of crashes the design window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
永远不要修改 .designer.cs 文件。无论您在其中做什么,下次您在设计器中编辑表单时,它都会被覆盖,因此您必须再次执行此操作。我认为没有任何理由不将此代码放入 Form 构造函数或
Load
事件中...Don't modify the .designer.cs files, ever. Whatever you do in it, it will be overwritten the next time you edit your Form in the designer, so you will have to do it again. I don't see any reason not to put this code in the Form constructor or the
Load
event...你的最后一句话就是答案。如果有什么需要特殊处理,请在分部类的用户部分进行。即使在您的情况下(我推测),这也需要在设计器代码运行之前手动创建一个组合框。
我唯一一次接触设计器代码是当我简单而快速地想要更改一些我确信能够在 VS 的代码生成中幸存下来的内容时,例如绑定中的属性名称。
Your last sentence is the answer. If anything needs special treatment, do it in the user part of the partial class. Even if in your case (I'm speculating) this would require creating a ComboBox manually before the designer code runs.
The only time I touch the designer code is when I simply and quickly want to change something that I'm sure will survive the code generation of VS, e.g. a property name in a binding.
Designer.cs 文件告诉您不要修改:
如果您有修改,请在
InitializeComponent
之后在 Form 构造函数中进行修改:...或者在
this.Load
事件上进行修改:The Designer.cs file tells you not to modify:
If you have modifications then make those in your Form constructor after
InitializeComponent
:... or, on a
this.Load
event: