2017-07-07 197 views
0

如何使多個參數多於兩個? CustomButtonClickEventArgs被許多地方共享,我不想修改。如何將表示ComboBox位置的ActiveRow和ActiveCol參數添加到ComboBoxCustomButtonClick事件中,如下所示,我期望的是什麼?具有多個參數的C#事件

private void MyUC1_ComboBoxCustomButtonClick(object sender, MyUC.CustomButtonClickEventArgs e, int ActiveRow, int ActiveCol) 

聲明:

public class CustomButtonClickEventArgs : EventArgs 
    { 
     public readonly int Index; 

     public readonly string Key; 

     public readonly string Tag; 

     public readonly Keys ModifierKeys; 

     public CustomButtonClickEventArgs(int index, string key, string tag, Keys modifierKeys) 
     { 
      this.Index = index; 
      this.Key = key; 
      this.Tag = tag; 
      this.ModifierKeys = modifierKeys; 
     } 
    } 

public delegate void CustomButtonClickEventHandler(object sender, CustomButtonClickEventArgs e); 

ComboBox located in Grid Cell(1,1)

+0

你可以添加一個裝飾器/包裝到CustomButtonClickEventArgs添加ActiveRow和ActiveCol參數? – Andrew

回答

2

您剛纔定義的事件參數(EventArgs的)。你需要的是一個定義方法外觀的委託。

也許這樣?

public delegate void CustomButtonClickEventHandler(object sender, MyUC.CustomButtonClickEventArgs e, int ActiveRow, int ActiveCol); 

當你定義的事件,它需要這個代表:

public event CustomButtonClickEventHandler ComboBoxCustomButtonClick; 
+0

新的CustomButtonClickEventHandler適用於多個參數。我曾經只提出兩個論點。現在我知道它可以是更多的數字。接受答案。 – qtg

+0

它基本上是一個方法定義的藍圖。 –

0

我定義爲低於新CustomButtonClickEventHandler。

public delegate void ComboBoxCustomButtonClickEventHandler(object Sender, int ComboBoxCol, int ActiveRow, int ActiveCol, CustomButtonClickEventArgs e); 

[Category("ComboBox"), Description("Occurs when a custom button of the ComboBox is clicked.")] 
public event ComboBoxCustomButtonClickEventHandler ComboBoxCustomButtonClick;