Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...