Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

c# - How to modify code in 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);

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.

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.

Thanks for any suggestions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...