How to delete “empty code templates” in Visual Studio 2019 - c#

My professor took off points on an assignment for “leaving Empty Code Templates throughout my submission”. I’ve included a picture of what he was referring to. If anyone could help explain how to remove these?
I tried deleting them, hoping it would be all fine but I just get an error when I go back to my form.

As mentioned by Blue in a comment
Click on the associated controls in the designer view, and click the lightning bolt to view events. Delete them from there and you should be free to delete the leftover code.
It is a bad idea to edit event code signatures outside the designer.
Make sure you open the designer often or have frequent version control to avoid file corruption.

a friend just fixed it for me, she said: “ just delete what you want to delete and when u go back to ur program and it has that error click on “go to code” on the top right corner and delete the part that’s underlined in red”

Related

Visual Studio C# Form Designer not Allowing me to Select Elements

I'm fairly new to C#, I'm following along with an online tutorial, and I was working on building some forms when I noticed that the Visual Studio 2019 C# Form Designer was acting strangely. First every once in a while I would place an element on the form and then I wouldn't be able to select any other element, it would be stuck on that one element and clicking at all would cause the selected element to resize, rather than move like I would expect. That was annoying, but I was able to close the design window, and reopen it and it worked okay again, until it happened again usually after placing 2 or 3 elements with no issue.
But then a new problem started happening, where the place that I click on the design is offset to the left and down. So In order to select an element I have to move to the right and up, in order to be able to select the element I want to edit. The red rectangle in the picture below shows the spot where I would have to click in order to select the "Create Tournament" label. This is much worse than the first problem, and closing and reopening the design window doesn't help, nor does restarting Visual Studio or even resetting my computer. This is also happening across all of my forms. I was wondering if anyone knew what was going on or how I could fix this. Any help would be greatly appreciated, thank you.

VS crashes and winforms data lost

I am developing an application using Visual Studio 2019 and I am designing winforms.
Visual Studio commonly crashes when I am creating the forms by freezing, and recently my designed winform has somehow disappeared (even though I saved it). When i open it it shows as the default winform that is shown when a new one is created:
When I browse the solution explorer it seems that I can still see all the components I had added to the form:
Finally, when I try to restart and manually add the components back, I get an error message saying that the component can't be added due to duplication - which is probably because they are somehow still there (as shown in the solution explorer) but the data has been corrupted somehow:
If anybody has any idea of how to recover the data and the winform, I would very much appreciate it. If any additional information is required, please let me know. Thanks!
According to your description, first, the controls actually exist, but they are not
displayed in the design window.
You can try to check whether the. add statement of each control added to the window still
exists in the .Design.cs file.
If not, you can add it manually.
Second, solution explorer shows the missing components, but there is an error in adding
components. It means that only the declaration of this control in the .Design.cs file does
not assign a value to this control. You can delete the declaration of the component in the
.Design.cs file, and then add the component in the design interface.
Result:

Visual Studio Customize What gets Outlined

I just upgraded to VS2017, and I'm having issues with the Code Outlining. Specifically, I want methods, regions, classes to stay outlined and collapse/expand as they did in VS2015, but I don't want if/for and other code blocks to be outlined. I want them to always be expanded.
Anybody know how to do this?
Thanks
Turns out I found it myself in the settings.
In the Menu bar, Go to Tools->Options, then follow the trail in the image below to get the fix.
VS Settings
(I don't have enough reputation to post the image, so the link goes to it. If you don't want to go there, it's Tools->Options, then Text Editor->C#->Advanced and uncheck "Show outlining for code level constructs")

Deleting an item off of Windows Forms in both the Code.cs and Code.cs[design] properly

When I'm making a Windows form application, and I use the toolbox and drag an item onto the form, I get a nice tool on the form, like button, listbox, etc. When I double click on the button, listBox, etc it goes to the text code part where all the delegates are. Also known as the event handlers. But what happens when I want to delete an item on the visual part of the application (the Code.cs[design] part)? I select it, then right click it and then delete it. It's off the screen. But, the problem is with all the event handlers. They're still left in the text-based code section but I don't need them there at all, and they generate a whole bunch of errors because references are gone, etc.
So, basically, I'm asking someone on the forum how to completely get rid of a button, listBox, both the visual part of it in code.cs[design] and in the code.cs part? I don't want to go line-by-line in deleting junk, I want to get rid of the button/listBox and it's accompanying code in one fell swoop.
It will delete such an automatically added event handler. But only if you didn't modify it and left it untouched with no code added. Visual Studio will not delete code that you have written. The reason for that should be obvious.
If this happens a lot then you need to get a pair of scissors and cut the mouse umbilical cord. Design first, program later.
I can't be done and it shouldn't.
You first delete the visible control and after that you delete the code stubs.
The handler assignments in the Designer.cs are then being deleted with the visible control automagically, as they were created.
Just make sure to get the order right: first delete the controls then the code.
Unless you mix those up there is no need to ever edit the designer.cs file. The code may contain important stuff you wrote. Therefore is is not deleted by studio.
You create it, you delete it! Two steps, period.
PS: The code stubs are (unfortunately) added chronologically. It would be nice if they were grouped by the controls they belong to. If you are in doubt, you can always use the 'find all references' command to find those methods buried in the past..
If you have a code stub generated, delete the method. Once that's done, Click on your 'forms view' - you will have an error screen shown.
Click on the link, and it will being you to the designer view, with your cursor shown on a specific line. Delete this line of code. Having that done, you could then delete the physical element from your designer.

C# Designer: Removing redundant code from Design.cs

I have a form which has several buttons, labels and other stuff on it, but the designer appears to remember old elements of that form that have previously be deleted.
Is there anyway to 'refresh' the form.Designer.cs code to inform it what elements are currently on the form and what elements are not.
Cheers for the help in advance ;)
If they are still in the designer file after a restart of VS and a re-open of the designer then they haven't been deleted yet. I've seen several cases where people think that variables are deleted but what's happen is they've been moved off of the visible area of a form. So they still exist but they're not doing anything interesting.
What you can do is close the designer, carefully delete all of the variables you want from the designer.cs file, recompile and re-open the designer. Before doing this I would backup the file though as it is possible to mess up your control by doing this.

Categories