加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在Visual Studio 2010中不使用设计模式的情况下为事件查找

发布时间:2020-12-15 08:14:14 所属栏目:百科 来源:网络整理
导读:有没有办法知道Visual Studio 2010中的事件需要什么参数? 假设我有一个DropDownList控件,我想将一个方法绑定到“OnSelectedIndexChanged”,我会做这样的事情 在ASPX文件中: asp:DropDownList ID="lstMyList" runat="server" OnSelectedIndexChanged="lstMy
有没有办法知道Visual Studio 2010中的事件需要什么参数?

假设我有一个DropDownList控件,我想将一个方法绑定到“OnSelectedIndexChanged”,我会做这样的事情

在ASPX文件中:

<asp:DropDownList ID="lstMyList" runat="server" OnSelectedIndexChanged="lstMyList_SelectedIndexChanged"></asp:DropDownList>

在代码隐藏中:

protected void lstMyList_SelectedIndexChanged(object sender,EventArgs e) 
{
    ...
}

有没有办法知道方法需要什么参数? (在这种情况下,发件人的对象和事件的EventArgs参数.)

我知道您可以通过在设计模式中双击正确的事件轻松创建方法,但它会使您的代码混乱,所以我不想使用它.

谢谢!

解决方法

您可以通过“转到定义”(F12)找到适当事件的参数,找出它使用的代理类型,然后进行定义.在这种情况下,SelectedIndexChanged事件的类型为 EventHandler,其定义如下:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public delegate void EventHandler(
    Object sender,EventArgs e
)

您也可以通过搜索网络或按F1并在帮助中搜索来查找此信息.

I know you can easily create the method by double-clicking the right event in Design Mode,but it does a mess with your code so I prefer not to use it.

我认为你应该试着克服你对使用设计师的恐惧.通过不使用Visual Studio中的代码生成功能,您最有可能浪费更多的时间来节省生产力,而不是通过保护自己免受设计人员搞乱代码而节省的潜在时间.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读