识别UserControl(c#)上的点击事件 [英] recognize click event on UserControl (c#)

查看:663
本文介绍了识别UserControl(c#)上的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在c#中开发了一个UserControl.控件名称为myControl.
UserControl有一个pictureBox,复选框,标签等.

我希望在且仅当用户单击pictureBox时才处理整个UserControl Click事件. (因为我在另一个控件中使用了myControl,并且仅当单击myControl中的pictureBox时,我才想捕获myControl Click事件).

我该怎么办?

谢谢

Hello,

I develop a UserControl in c#. Control name is myControl.
The UserControl has a pictureBox, checkbox, label, etc.

I want the whole UserControl Click event to be handled if and only if the user clicks on the pictureBox. (Because I use myControl in another control, and I want to catch myControl Click event if and only if the pictureBox in myControl was clicked).

How can I do that?

Thanks

推荐答案

您可以使用此
You can use this
public void main()
{
    pictureBox.Click += new EventHandler(pictureBox_Click);
}
public void pictureBox_Click(object obj, EventArgs ea)
{
    // This get executed if the pictureBox gets clicked
}


这篇关于识别UserControl(c#)上的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆