• <small id='iXjjd'></small><noframes id='iXjjd'>

  • <i id='iXjjd'><tr id='iXjjd'><dt id='iXjjd'><q id='iXjjd'><span id='iXjjd'><b id='iXjjd'><form id='iXjjd'><ins id='iXjjd'></ins><ul id='iXjjd'></ul><sub id='iXjjd'></sub></form><legend id='iXjjd'></legend><bdo id='iXjjd'><pre id='iXjjd'><center id='iXjjd'></center></pre></bdo></b><th id='iXjjd'></th></span></q></dt></tr></i><div id='iXjjd'><tfoot id='iXjjd'></tfoot><dl id='iXjjd'><fieldset id='iXjjd'></fieldset></dl></div>

  • <tfoot id='iXjjd'></tfoot>
  • <legend id='iXjjd'><style id='iXjjd'><dir id='iXjjd'><q id='iXjjd'></q></dir></style></legend>

      <bdo id='iXjjd'></bdo><ul id='iXjjd'></ul>
      1. 带有自定义参数的 EventHandler

        时间:2023-09-15

            <i id='rt5C1'><tr id='rt5C1'><dt id='rt5C1'><q id='rt5C1'><span id='rt5C1'><b id='rt5C1'><form id='rt5C1'><ins id='rt5C1'></ins><ul id='rt5C1'></ul><sub id='rt5C1'></sub></form><legend id='rt5C1'></legend><bdo id='rt5C1'><pre id='rt5C1'><center id='rt5C1'></center></pre></bdo></b><th id='rt5C1'></th></span></q></dt></tr></i><div id='rt5C1'><tfoot id='rt5C1'></tfoot><dl id='rt5C1'><fieldset id='rt5C1'></fieldset></dl></div>
              <bdo id='rt5C1'></bdo><ul id='rt5C1'></ul>
              • <tfoot id='rt5C1'></tfoot>
                  <tbody id='rt5C1'></tbody>

              • <legend id='rt5C1'><style id='rt5C1'><dir id='rt5C1'><q id='rt5C1'></q></dir></style></legend>

                  <small id='rt5C1'></small><noframes id='rt5C1'>

                1. 本文介绍了带有自定义参数的 EventHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Google 上找了大约一个小时的答案,但没有找到我想要的答案.

                  I've been looking for an answer for about an hour on Google but I did not found exactly what I'm looking for.

                  基本上,我有一个静态 Helper 类,可以帮助执行我在应用程序中经常做的许多事情.在这种情况下,我有一个名为CreateDataContextMenu"的方法,它在给定的 TreeView 控件上创建上下文菜单.

                  Basically, I have a static Helper class that helps perform many things I do frequently in my App. In this case, I have a method named "CreateDataContextMenu" that creates a context menu on a given TreeView control.

                  public static void CreateDataContextMenu(Form parent, TreeView owner, string dataType)
                  { ... }
                  

                  TreeView 所有者是我将关联上下文菜单的控件.

                  TreeView owner is the control in which I will associate my context menu.

                  稍后我将 Click 事件添加到 MenuItem,如下所示:

                  Then later on I add a Click event to a MenuItem like this:

                  menuItemFolder.Click += new System.EventHandler(menuItemFolder_Click);
                  

                  我在这里遇到的问题是我想将所有者"和数据类型"作为参数传递给 menuItemFolder_Click 事件.

                  The problem I have here is that I want to pass "owner" and "dataType" as arguments to the menuItemFolder_Click event.

                  我尝试了以下方法:

                  menuItemFolder.Click += new System.EventHandler(menuItemFolder_Click(sender,e,owner,dataType));
                  (...)
                  private static void menuItemFolder_Click(object sender, System.EventArgs e, Treeview owner, string dataType)
                  {...}
                  

                  但它根本不起作用.这样做可能太天真了,但我对事件处理程序还不是很满意.

                  But it doesn't work at all. It might be very naive of me to do it that way but I"m not very comfortable with event handler yet.

                  知道我该怎么做吗?我的第一个猜测是我需要为这种特定情况创建自己的 EventHandler.我是否朝着正确的方向前进?

                  Any idea on how I could do that? My first guess is that I need to create my own EventHandler for this specific case. Am I going in the right direction with that?

                  推荐答案

                  你应该创建一个 lambda 表达式 调用带有额外参数的方法:

                  You should create a lambda expression that calls a method with the extra parameters:

                  menuItemFolder.Click += (sender, e) => YourMethod(owner, dataType);
                  

                  这篇关于带有自定义参数的 EventHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么事件处理程序的返回类型总是 void? 下一篇:检测表单何时关闭c#

                  相关文章

                2. <tfoot id='kuMeZ'></tfoot>
                  <legend id='kuMeZ'><style id='kuMeZ'><dir id='kuMeZ'><q id='kuMeZ'></q></dir></style></legend>

                      <small id='kuMeZ'></small><noframes id='kuMeZ'>

                      <i id='kuMeZ'><tr id='kuMeZ'><dt id='kuMeZ'><q id='kuMeZ'><span id='kuMeZ'><b id='kuMeZ'><form id='kuMeZ'><ins id='kuMeZ'></ins><ul id='kuMeZ'></ul><sub id='kuMeZ'></sub></form><legend id='kuMeZ'></legend><bdo id='kuMeZ'><pre id='kuMeZ'><center id='kuMeZ'></center></pre></bdo></b><th id='kuMeZ'></th></span></q></dt></tr></i><div id='kuMeZ'><tfoot id='kuMeZ'></tfoot><dl id='kuMeZ'><fieldset id='kuMeZ'></fieldset></dl></div>
                        <bdo id='kuMeZ'></bdo><ul id='kuMeZ'></ul>