User Control Click - Windows Forms

前端 未结 2 1500
不思量自难忘°
不思量自难忘° 2020-12-19 04:03

I have a custom user control on my windows forms. This control has a few labels on it.

I will be dynamically displaying an array of these controls on my form which w

2条回答
  •  执笔经年
    2020-12-19 04:39

    User control's click event won't fire when another control is clicked on the user control. You need to manually bind each element's click event. You can do this with a simple loop on the user control's codebehind:

    foreach (Control control in Controls)
    {
        // I am assuming MyUserControl_Click handles the click event of the user control.
        control.Click += MyUserControl_Click;
    }
    

    After this piece of code workd, MyUserControl_Click will fire when any control on the user control is clicked.

提交回复
热议问题