Remove unwanted code in Visual Studio 2010? - visual-studio-2010

When I'm creating a GUI of Windows Forms in Visual Studio, I sometimes happens to double click on a component and get some auto generated code. To remove this unwanted code, I read somewhere, but I can't remember where, to remove this code you shouldn't delete it, it should be done in some other way to prevent future errors. How do I remove this unwanted code in Visual Studio the right way?

Normally, I simply delete the code and nothing bad come out of it. At worse, when you try to build, you'll get an error in the designer.cs saying some code is not found. Simply delete that and everything will work fine.
You can also use Ctrl+Z when you double-click, but it will delete the component you double-clicked on and you'll have to add it again to your form.

AFAIK, the answer is NO. Unless there is some specific add-ins from Microsoft (Which I am not aware off) which enables it.
So, You will have to manually delete the unnecessary code which have been auto generated.

Control-Z - it will remove the event handler registration from the YourForm.designer.cs file and also the method from YourForm.cs file.
A warning box will come up as soon as you press Control-Z, just click yes.

Just remove it from the XAML code. For example, if you double click a button, search for Click="button1_Click" in your XAML and delete it.
If you created a Windows Forms project, go to Solution Explorer and open file file Form.Designer.cs and from function InitializeComponent() delete this line:
this.button1.Click += new System.EventHandler(this.button1_Click);

Related

Edit.GoToAll command in Visual Studio does not show file name suggestions

Context
I use this command with the shortcut Ctrl + T (alternatively Ctrl + ,) to quickly navigate to files in my solution (WPF app if relevant). As I do not remember the exact file names I would (until recently) use the suggestions that were showing below the prompt to find my files as in this example:
Navigation with suggestions
Source of example
Since I last started VS I get none:
Navigation without suggestions
Attempts
Restarting and updating visual studio didn't help. Neither did deleting the .vs file of the solution. I also toggled the statement completion fields in Tools > Options > Text Editor > All Languages, saw no change.
I believe this might be some Intellisense error but I am not sure. I would be thankful for any guidance or information.
One possible cause is somehow you had collapsed the list. If you hover over the point in the picture below you should get a resize handle. Grab it and pull it down to get your list back.

How do I stop visual studios from adding functions while creating forms?

I've always been annoyed that visual studio always thinks a double click means create an action function while creating a form. Sometimes I double click on a label to change the text like I do in other programs then I have to delete code and click back to the form editor.
Is there a way to stop this when I'm setting up a form then turn it back on when I am ready to code?
Thank you for the help.
This is probably better off as a comment, but I lack the rep to comment.
You can't stop this behaviour.
The simplest (and as far as I'm aware, only) "solution" (read: workaround) is to just CTRL+Z twice when this happens (doing it once will cause your form designer to show an error, because the event binding will exist in the form, but the associated code won't exist).

Microsoft visual studio screen problem

I am having a problem thats not about the code, it's about the screen in Microsoft visual studio 2008.
Actually problem is i created one utility from couple of weeks i didn't opened that utility today i opened (in Microsoft visual studio the screen appearing blank no controls are visible in that.But all the controls properties are there. I tried a lot but i didn't get solution. Last when the same thing happened i created the controls again. Now i don't want to go to create all the controls again. If any one have the solution please help me.
Before screen is like this:
Now its blank (like new page)
From your description I'm not sure if this is a application/code build issue or an IDE issue, what you could try is to reset the settings in visual studio and see if this helps.
You can do this by going to Tools -> Import/Export settings and then following the wizard to reset the settings, you may also want to perform a backup before resetting them (this is also part of the wizard) then they can be restored if this causes you further issues.
I don't have a copy of 2008 available at the moment so some menu entries may be slightly named different.
Hope this helps!
EDIT:
Now there is more information, this looks like there may be a problem with the code in the
InitializeComponent
method of the form.designer file (e.g. if you are using c# this would be something like Form1.Designer.cs and can be found by expanding the corresponding form in the solution explorer), if you remove/comment the lines that say
this.Controls.Add(this.NameOfControl)
(NameOfControl is where you would see your declared controls name)
then you get the behaviour that you are seeing, the controls do not render as they are never added to the forms controls collection but as they are declared you will still see them in the properties drop down and wont be able to add another control with the same name.

Folder imported in Code Snippets Manager not showing in text editor - Visual Studio 2010

In the Code Snippet Manager I chose "Language: Visual C#" and added a folder containing one .snippet file I created.
Then, when editing a .cs file, I try to insert a snippet using ctrl+k ctrl+x but my newly added folder does not show in the list.
I'm I missing something? Do you have to specifically tell IntelliSense which snippets you want to have shown in the list when trying to insert a snippet? I thought that was done by choosing "Language: Visual C#" in the Code Snippet Manager...
Thanks!
Does your folder (and the snippet, when you click on the folder) show up in the Code Snippets Manager? If not, then maybe it didn't get added correctly (or VS 2010 didn't parse the snippet successfully, or didn't recognize that the file was a valid snippet)? I believe the folder will only show up in the Code Snippets manager if VS2010 finds something it recognizes as a valid snippet, so if there are any parsing issues, there might be problems.
If the folder does show up correctly, then I also did notice that, when you hit Ctrl-K, Ctrl-X, unlike in Visual Studio 2008, newly added snippet folders appear to be sent to the bottom of the list instead of being sorted. In VS 2008, I was able to stick an underscore before the folder name (e.g. _Code Snippets) and have it show up on top. Not so, here. I realize this might be an idiotic suggestion, but maybe it's at the bottom of the list instead of sorted in with the rest? I know, I know, but I had to ask...
Barring that, maybe there is a caching issue with IntelliSense?
Not much of an answer, I know, but maybe it will jog someone's memory?

Visual Studio 2005: Please stop opening my CS files in "Design Mode"!

I think it's associating my Web Service's CS files with the related ASMX files. But whatever's happening, I can't double-click to open the CS files - I have to "view Code" or it opens in the designer.
Anyone know how to turn off this automatic behavior? I just want to edit the code!
Try right-clicking, select "Open with...", mark "CSharp Editor" and select "Set as Default".
That works for avoiding the WinForms Designer.
I found this question when trying to deal with a similar problem. I had a C# class in a file and whenever I double clicked on the file it would try to open in design mode but design mode was meaningless for this class. I just want to see the code.
I found that adding the [System.ComponentModel.DesignerCategory("")] attribute to my class fixed this.
In the Solution Explorer view, click the "Show All Files" icon. This will put "+" symbol next to each of your files. Click the + and it will expand to show the .CS file which holds the ASMX's code. At this point, double click that file instead.
For some reason VS2005 seems to have this a bit backwards when it comes to webservices. To open a webservice in code view, double-click the .asmx file, not the .asmx.cs file.
I guess it makes a bit of sense, as there's nothing to "design" when it comes to a webservice, but it's counterintuitive if you've been working with .aspx files.
In my experience, if you find that the wrote editor, that is the non-default editor, is opening when double-clicking on a file within the Solution Explorer then something is wrong with the underlying project's User Options file (.user) or the solution's User Options file (.suo). (I am not sure which, but I suspect the settings are stored in the .suo file.) Deleting the the .suo and all project .user files solved the problem.
I personally, set the Form Editor as my default editor for forms at the beginning of a project. After the forms are stable and require less user-interface design changes, I switch the default editor.

Resources