In work and in home I have VS2010 installed. But in work I have this one cool feature. On the code behind file I have two drop downs. When I select some object in the left one lets say a testButton or Default2 (a page class), on the right one I get all available events for that object and when I select an event Visual Studio autogenerates it in my code-behind file. In my home VS I actually have does 2 drop downs but they work different. I have available objects on the right one but when I select for example the testButton it shows me the aspx page and points this button :/ Should I set sommething in the VS configuration or maybe in work I have some addon which I'm not aware of? Any ideas?
This is not a VB-exclusive feature.
What you're looking for is called a navigation bar. In Visual Studio options, open Text Editor → C# → General, and you'll see an option called Navigation Bar. Enable it and click OK.
However, I believe this bar works a bit differently in VB and in C#. In C#, it only lists the existing classes and their methods; in VB, it will list all your controls and their events even if those don't exist yet.
Ok I think I've found the answer. It seems that this feature is only available when the current file is in VB.Net. In my opinion this suks :/
You need to go the design view, in the Properties box, click on Events (lighting bolt) and double click on the events you want to code behind:
(source: byte.net)
#shin is correct, this is a VB.NET only feature; Microsoft only had feedback reports dating back to 2004 mentioning this feature, so I have opened a new bug request with Microsoft regarding this; and also added feedback to Visual Studios account on UserVoice...
https://connect.microsoft.com/VisualStudio/feedback/details/688175/vs2010-c-add-page-event-handlers-to-asp-net-using-codebehind-navigation-bar-the-same-way-as-in-vb-net
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2244558-allow-c-to-add-event-handlers-to-classes-using-co
I encourage everyone who this issue effects to go and vote up & confirm this issue with them.
I dislike that C# doesn't provide such a useful time-saving function.
Up to Visual Studio 2010, only Vb.net has this feature: on code-behind page, the code panel upper-left drop down shows a control's name, and the right drop down shows this control's available events. When clicking this event we can get the code-block for this event. This feature is not available in C#.
Without above feature, we can still get a control's available events for both C# and Vb.net: We must select the control on the aspx page and choose the design view at the lower left corner, then on the Properties panel click the Event button (the lighting sign), then available actions will be shown, double-click the name of the event you want, the event code will be generated in code-behind.
It is most certainly is a VB only feature and has been reported on numerous occassions to Microsoft.
It is possible to see all the available Events in C# & Asp.net too, but not inside code window as possible in VB. But you can see all Events of any selected Control in its Property Window. Open Properties, then Click Events.
This and the feature to generate event handlers without having to switch to Design view for C# is finally coming in Visual Studio 2012. It was about time.
Even the 2012 feature is not enough. You still have to guess for Page level events (Init, PreRender, etc) and also files that haven't already been filled out for you like Global.asax, which depending on the template you started with may or may not have all the event handlers already specified.
Agreed that Event Handlers is one of the things VB has for years and years and years handled way better than C#. I can't count the number of times I've had to remind a fellow C# developer that some events do, in fact, exist.
Related
I'm new to C# and delegates, however, from what I've gathered, they say if this event happened run this method. But in Visual Studio (community 2017), I can't figure out where/how I am meant to go about defining/attaching them.
I'd appreciate an answer as I'm trying to go about switching a program I've previously written in Python over to C#.
I've looked through documentation, I've looked over questions already asked here, and none of them seem to give me the information I'm after.
To add delegates (in this case they're typically called "event handlers") to UI controls in WinForms, you should:
Select the control in the visual designer
Look at the Properties windows
Click the lightning bolt to view the events.
Either double-click the blank space next to an event to auto-generate a handler, or single-click and select an existing handler from the dropdown.
I've recently started using C# after years of using VB.NET
When using Visual Studio, using VB.NET, on the code behind files (.aspx.vb) i could select from a list of controls in my markup file (.aspx) and then select an event to automatically put into my code behind.
I've noticed with C# I don't get this option:
Why is this? Or is my intellisense just playing up?
In c# you can't add events like vb.net project, two dropdowns in C# project for class and its methods. you have to use property window to add events or double click on the controller it will add default event for the control.
If you are looking for a list of Events you will need to be on the form, not in code behind.
Select the Form right click, go to Properties, at the top of the Properties bar you will see a lightning bolt, click this and you will see all available events for that Form.
in c# how can I get the available events of a class in order to begin programming code inside of it. I know that in form or usercontrol you can select the control and click the events button and click on the selected event to begin coding, but I mean a derived class which I want to code its methods or events.
Thanks!
The simplest way is to look in the documentation, to be honest.
If you're within the designer, your approach of using the properties window will work for other controls (buttons, textboxes etc) as well... and if you're in the IDE, you can type this. from any instance context (e.g. the constructor) and get a list of members up, including the events.
I would still suggest reading the documentation though - MSDN allows you to look at all members, or just the events (or methods, or whatever) at any one time. It's not terribly hard to peruse the list that way - and you can then check the details of the event so you can make sure you're using it properly, rather than just by guessing based on the name.
EDIT: As Aren mentions, there's also the Object Browser. Not my personal preference, but it's an option.
The events are listed in the IntelliSense popup window you'll get when you type the class reference variable name followed by a dot. They have a lightning bolt icon.
Many more organized ways to know what a class can do. You could read its documentation. Or browse its source code. Or use Reflector if there isn't any.
in Visual Studio 2010, they have got this new Help Library Manager where you can check for MSDN updates and download any updates or go to online directly. (you can also install Vendor API docs quite easily as well)
i want to ask abt Sharpdevelop.
Can i change the control's event name in sharpdevelop ? I want to add "_" like in visual studio.
For Example, button click event in Sharp develop defaulted to Button1Click. can i change to Button1_Click like in visualstudio ?
Thanks.
Mike Webb's answer is the only way to generate an event handler method name with an underscore without modifying SharpDevelop's source code.
Lex Li's answer is also correct. There is no option in SharpDevelop to enable automatic generation of event handler method names that use an underscore. The only way currently is to modify the source code. It is a fairly straightforward code change.
Download the source for SharpDevelop.
Extract the code.
Locate the EventBindingService class (src\AddIns\DisplayBindings\FormsDesigner\Project\Src\Services\EventBindingService.cs)
Locate the CreateUniqueMethodName method.
Modify the single line of code in this method to use an underscore in the string format:
return String.Format("{0}_{1}", Char.ToUpper(component.Site.Name[0]) + component.Site.Name.Substring(1), e.DisplayName);
Build SharpDevelop from source code by running src\DebugBuild.bat or src\ReleaseBuild.bat
Then when you use your customised version of SharpDevelop and double click a button in the forms designer, for example, you will get an event handler with a name like "Button1_Click".
At some point in the future SharpDevelop 4 will allow this with an option that can be selected in Tools - Options.
Yes. If you go into design and look in the properties window for the control you will see a few icons at the top. One of these should give you the list of events (in VS it is a lightning bolt). In the left hand column are the linkable events and in the right hand column are the functions that are called when the events are triggered.
Simply rename the left hand field and make sure you have the function named correctly in code as well. You can also type a name into the left hand field and then double click inside it to generate the function automatically.
The underscore is evil to some people, like me :)
Well, if you do want the underscore, check out SharpDevelop source code and locate that part and modify it. It is open source, so you can do whatever you like to please yourself. I did not see a setting available somewhere, so modify the source code seems to be the only way to achieve your goal.
I know this is an old thread but in SharpDevelop v4.3 (v4.x - v5.x) there is a solution to this. In the past i've had to use the above method, however this one is much faster and easier.
Launch SharpDevelop and check the following setting:
Tools > Options > Windows Forms Designer > General > "Generate Visual Studio Style Event Handlers"
I assume I am not the first one having this problem and I am normally pretty good at googling for stuff but in this case I didn't succeed in finding a solution, so I'll post it here.
I have some experience in VB.NET and WinForms, now I am working on an ASP.NET project and I decided to do it in C#, so I can learn more technologies / languages.
I have been creating even handlers for controls by clicking the "Events" lightning bolt on the Properties windows and then double-clicking on the event name. That automatically creates an event procedure, selects it for the handler and opens the code behind with the procedure declaration already there. It has been working fine until now. I just added a FormView object and I am trying to create a handler for the ItemCommand event. As usual, I am double-clicking on "ItemCommand" under Events and it populates it with "fvMembers_ItemCommand" but it does not jump to the code behind and it does not create the actual function. I just tried doing the same thing in a different project that was created by somebody else and it looks like it's working fine there.
Any suggestions?
Thanks!
The best recommendation for this is the following. Clear out the definition of the event, by right clicking and selecting "remove". Save any progress that you have, exit visual studio, and then go back to the project.
Be sure that you don't have any build errors then try it again. I've found that VS just needs a re-start every so often.
Now, don't I feel stupid :)
I didn't even have to close VS. I closed and re-opened the solution and it appears to be working now. I just had a situation yesterday where an ObjectDataSource wasn't reflecting the latest structure, "Refresh Schema" wasn't helping either. Rebulding the solution didn't help either but it helped restarting VS. I don't think I ever had to re-start VS while working on WinForms projects but it looks like working on ASP.NET requires frequent VS restarts.
Thank you for your help!