为事件创建一个空白" SelectionChangeCommitted"对于ComboBox数组

时间:2014-06-22 17:23:36

标签: c# arrays combobox void eventhandler

我有一个包含5个组合框的数组。我想为事件创建一个空白" SelectionChangeCommitted"对于整个阵列,可以确定从哪个组合框中调用空隙。这是包含5个空隙的当前代码。每个组合框一个。

private ComboBox[] statsValues;

public frmMain()
    {
        InitializeComponent();
        statsValues = new ComboBox[5];
        for (byte b = 0; b < statsValues.Length; b++)
        {
            statsValues[b] = new ComboBox();
            statsValues[b].Location = new System.Drawing.Point(69, 193 + 30 * b);
            statsValues[b].DropDownStyle = ComboBoxStyle.DropDownList;
        }
        Controls.AddRange(statsValues);
        statsValues[0].SelectionChangeCommitted += new System.EventHandler(cmbSTR_SelectionChangeCommitted);
        statsValues[1].SelectionChangeCommitted += new System.EventHandler(cmbDEX_SelectionChangeCommitted);
        statsValues[2].SelectionChangeCommitted += new System.EventHandler(cmbCON_SelectionChangeCommitted);
        statsValues[3].SelectionChangeCommitted += new System.EventHandler(cmbINT_SelectionChangeCommitted);
        statsValues[4].SelectionChangeCommitted += new System.EventHandler(cmbWIS_SelectionChangeCommitted);
    }

    private void cmbSTR_SelectionChangeCommitted(object sender, EventArgs e)
    {
        //Code...
    }

    private void cmbDEX_SelectionChangeCommitted(object sender, EventArgs e)
    {
        //Code...
    }

    private void cmbCON_SelectionChangeCommitted(object sender, EventArgs e)
    {
        //Code...
    }

    private void cmbINT_SelectionChangeCommitted(object sender, EventArgs e)
    {
        //Code...
    }

    private void cmbWIS_SelectionChangeCommitted(object sender, EventArgs e)
    {
        //Code...
    }

我想为所有人创建一个空洞,可以确定从哪个组合框中调用它。

1 个答案:

答案 0 :(得分:0)

假设&#39;虚空&#39;意味着事件处理方法&#39;,

private void cmbALL_SelectionChangeCommitted(object sender, EventArgs e)
{
    ComboBox thisOne = (ComboBox)sender;
    //Code...
}