Microsoft Visual Studio和C#:如何将事件视觉添加到控件? [英] Microsoft Visual Studio and C#: How to Visually Add Events to Controls?

查看:282
本文介绍了Microsoft Visual Studio和C#:如何将事件视觉添加到控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个愚蠢的问题,但是对于我来说,我找不到办法。

Perhaps this is a stupid question, but for the life of me I cannot find a way to do this.

如何添加一个事件处理程序在Microsoft Visual Studio(2008)中使用C#的形式的控件?

How would one go about adding an event handler to a control in a form in Microsoft Visual Studio (2008) with C#?

我可以手动执行,但打开该表单的Designer.cs文件,但我不能找到一种通过界面来做的方法。在MSVC 6中,使用C ++和MFC,您可以右键单击或其他一些操作,并找到该控件的所有可能事件的列表。然后选择它,它会弹出窗口,让您创建一个方法来关联该事件。在VB中,它更容易,您可以在代码中执行它,并列出方法下拉列表中的所有事件。

I can do it manually, but opening the Designer.cs file for the Form, but I cannot find a way to do it through the interface. In MSVC 6, with C++ and MFC, you could right click or some other action, and find a list of all the possible events for that control. Then you select it and it would bring up window letting you create a method to associate with that event. In VB it was even easier, you could do it in the code and it listed all the events in the method drop downs.

但是,我找不到任何排序在2008年与C#。 Intellisense有助于填写正确的方法信息。但是,它始终在Designer.cs文件中创建方法,而不是部分类的另一半。应该是。

However, I cannot find anything of the sort in 2008 with C#. Intellisense helps fill in the correct method information. However, it always creates the method in the Designer.cs file, not the other half of the partial class where it should be.

谢谢。

推荐答案

在设计器中,单击感兴趣的控件。

In the designer, click the control of interest.

在属性窗口点击F4来拿起它),应该有一个闪电图标。单击该图标可以转到该控件的可用事件列表。双击事件名称将连接一个存根处理程序,并带你到代码隐藏。

In the properties window (hit F4 to bring it up), there should be a little lightning bolt icon. Clicking the icon takes you to the list of available events for that control. Double-clicking the event name will wire up a stub handler and take you to the code-behind for it.

编辑:精明的读者会看到,贴图的截图是针对网络应用程序(whups) ,但对于winforms应用程序来说,这是完全相同的。

the astute reader will see that the posted screenshot is for a web app (whups), but it's the exact same thing for a winforms app.

这篇关于Microsoft Visual Studio和C#:如何将事件视觉添加到控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆