qtg
qtg

Reputation: 125

C# event with multiple arguments

How to make multiple arguments more than two? CustomButtonClickEventArgs is shared by many places, I don't want to modify. How to append ActiveRow and ActiveCol arguments which indicated the ComboBox location in a Grid into the ComboBoxCustomButtonClick event like below what I 'expected'?

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

declares:

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)

Upvotes: 0

Views: 3903

Answers (2)

Max Play
Max Play

Reputation: 4038

You just defined the Event Arguments (EventArgs). What you need is a delegate that defines how the method should look.

Maybe something like this?

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

When you define the event it needs this delegate:

public event CustomButtonClickEventHandler ComboBoxCustomButtonClick;

Upvotes: 2

qtg
qtg

Reputation: 125

my new CustomButtonClickEventHandler defined as the below.

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;

Upvotes: 0

Related Questions