简体   繁体   中英

Events list in Visual Studio 2015

Using VS2013 it was possible, at least with VB.NET, to double click on a control and then the default event would show up in the code file. Above this there was a pull down list of the other possible events for this control.

Now I'm working in VS2015 and in C#, but that list is not there. I can still double click on a control to get the default event, but I cannot add another event. I don't think I'm supposed to edit the designer file.

How do I do this now? Do I need to add events in the code file now?

for example I want to be able to drop a file on my windows application. So somewhere I need to add the event for this.

Winforms :
在此输入图像描述

Wpf:
在此输入图像描述
To see the properties window:
在此输入图像描述

Using VS2013 it was possible, at least with VB.NET, to double click on a control and then the default event would show up in the code file. Above this there was a pull down list of the other possible events for this control.

This is known as the Navigation Bar . You can toggle it on/off in Tools --> Options --> Text Editor --> {Select Language} --> Navigation Bar.

BUT ...the Navigation Bar behaves differently in C# than it does in VB.Net. It won't do what you want in C#, sorry!

To wire up an event using the IDE in C#, you have to first select the thing in question, then go to the Properties Pane and switch it to the Events view with the "Lightning Bolt" icon as Empereur Aiman has shown in his post.

C#, however, can do something that VB.Net cannot. With C#, you can wire up an event by writing a line of code in the editor and have the IDE generate the event stub for you . For instance, in the snippet below, a dynamic button is being created:

Button btn = new Button();

If you want to wire up its Click() event, you'd type in:

btn.Click +=

After the equals sign = is typed, you'd press {Tab} and the event stub will be generated for you:

    private void Btn_Click(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

如果将鼠标放在xaml代码中的Button关键字上,然后单击闪电图标,您将能够看到click事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM