自定义控件事件处理器

时间:2013-11-29 13:27:26

标签: c# events user-controls

我已使用自定义控件填充了flowLayoutPanel,并订阅了控件的MouseDown事件。如何创建EventArgs以评估自定义控件属性...

        for(int i = 0; i < fileInfoArray.Length; i++)
        {
            myViewerArray[i] = new SubstanceViewer(fileInfoArray[i]);
            myViewerArray[i].MouseDown += new MouseEventHandler(myViewerArray_MouseDown);

            flowLayoutPanel1.Controls.Add(substanceViewerArray[i]);
        }

所以我可以访问我的控件属性......

    private void myViewerArray_MouseDown(object sender, MouseEventArgs e)
    {
        richTextBox1.Text = [myControl?].info
    }

1 个答案:

答案 0 :(得分:1)

访问sender

private void myViewerArray_MouseDown(object sender, MouseEventArgs e)
{
    var myControl = sender as SubstanceViewer;
    richTextBox1.Text = myControl.info;
}