Reputation: 163
I have written a few C# projects in visual studio, but I have stumbled upon a problem I can't find a solution for online. Any button I add to a form, once I right-click and choose view code, I am taken to the code screen, BUT the code for that button IS NOT AUTOMATICALLY generated.
Please help me since I have to begin on my homework and I can't seem to get past this.
Upvotes: 0
Views: 3522
Reputation: 442
If the code is not showing even when you double-click, close the solution then run this batch file (which you create in the root folder of your solution/project):
@echo off @echo Deleting all BIN and OBJ folders... for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d" @echo BIN and OBJ folders successfully deleted :) Close the window. pause > nul
I name the batch file "AAA_DeleteBinObjFolder.bat" so that when sorted in File explorer it appear near top of file listing.
After closing the window displayed when you run the batch file, reload your solution or project and the code will appear in the code window.
Upvotes: 0
Reputation: 17194
In Design view, double-click the control for which you want to create a default event handler.
For you it is Button, so double-click that button to create a button_click event.
Other way:
In Right Click menu of the Button just go to Button's Properties, click the events symbol on top of the solution explorer window.
The Properties window displays a list of events for the selected control.
Double Click the Button_Click event which will create a button click event.
Upvotes: 0
Reputation: 98848
Just double click on the button, it will create a new event if none of events exist.
From: How to: Create Event Handlers in ASP.NET Web Pages
In Design view, double-click the page or double-click the control for which you want to create a default event handler.
Visual Web Developer creates a handler for the default event and opens the code editor with the insertion point in the event handler.
Also, can be related: How to: Create a Custom Double-Click Event
Upvotes: 3
Reputation: 223362
Instead of right clicking and viewing code, you should double click the button. That will take you to the attached event or if none exists, it will create a new one for the default event. In case of button its Click
.
You may see: How to: Create Event Handlers in ASP.NET Web Pages
In Design view, double-click the page or double-click the control for which you want to create a default event handler.
The above is also true for WinForm
Upvotes: 6