如何修改designer.cs中的代码 [英] How to modify code in designer.cs

查看:37
本文介绍了如何修改designer.cs中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WinForms 中创建了一个按钮并使用 VS 生成了一个事件.不知何故,按钮消失了.我检查了designer.cs 代码,发现指定按钮的代码已更改为将按钮定位在可见表单之外的某处.我将设计器代码更改为以下内容:

I created a button in WinForms and generated an event using VS. Somehow the button disappeared. I checked the designer.cs code and found code specifying the button had changed to locates the button somewhere out of the visible form. I changed the designer code to the following:

            // startButton
        // 
        this.startButton.Location = new System.Drawing.Point(118, 758);
        this.startButton.Margin = new System.Windows.Forms.Padding(6);
        this.startButton.Name = "startButton";
        this.startButton.Size = new System.Drawing.Size(140, 46);
        this.startButton.TabIndex = 17;
        this.startButton.Text = "Start";
        this.startButton.UseVisualStyleBackColor = true;
        this.startButton.Click += new   System.EventHandler(this.StartButton_Click);

在我尝试将按钮位置改回它应该是的位置之前,System.Drawing.Pont 被设置为 -256, 758.我使用文件中的另一个按钮位置来确定该值应该是118. 然而,当我重新启动程序时,按钮仍然不见了.为什么会发生这种情况以及如何恢复按钮.

Prior to my attempt to change the button position back to where it was supposed to be the System.Drawing.Pont was set at -256, 758. I used another button position in the file to determine that the value should have been 118. However, when I restart the program the button is still missing. Why is this happening and how do I get the button back.

如果我无法取回按钮,如果我删除 Designer.cs 中的按钮代码和事件处理程序会发生什么.然后我可以添加一个新按钮来替换旧按钮吗?只是想确保我不会做出损害整个程序的不可逆转的更改.

If I can't get the button back what happens if I delete the button code in designer.cs and the event handler. Can I then add a new button to replace the old. Just want to make sure that I don't make an irreversible change that compromises the entire program.

感谢您的任何建议.

推荐答案

设置控件属性的首选方法是通过设计"视图.

The preferred way to set the properties of your controls is through the Design view.

为此,您应该看到属性浏览器".使其可见的最简单方法是单击解决方案资源管理器"顶部的属性"按钮.

In order to do so you should have the "Properties explorer" visible. The easiest way to make it visible is to click in the "Properties" button on top of the "Solution explorer".

现在,在属性浏览器"的顶部,您会找到一个下拉列表,您可以在其中选择表单的所有元素.只需找到您要编辑的按钮,修改其位置属性并保存即可.

Now, on top of the "Properties explorer" you will find a drop-down list in which you can select all the elements of your form. Just find the button you want to edit, modify its Location property and Save.

关于你的另一个问题,你可以删除你的按钮并重新创建它,但它与事件处理程序的绑定将丢失,你将不得不重新创建它们.您可以通过属性浏览器"的事件"选项卡执行此操作.

Concerning your other question, you can delete your button and recreate it, but its bindings to the event handlers will be lost and you will have to recreate them. You can do this through the "Events" tab of the "Properties explorer".

这篇关于如何修改designer.cs中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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