开发者

UserControl event

开发者 https://www.devze.com 2023-02-18 09:43 出处:网络
I created a usercontrol, it consists of a picturebox with an image, add开发者_开发知识库 it to project, try to expose him to a click event, but it does not respond! What am I doing wrong?

I created a usercontrol, it consists of a picturebox with an image, add开发者_开发知识库 it to project, try to expose him to a click event, but it does not respond! What am I doing wrong? http://www.fileserve.com/file/yk9sjAu - usercontrol http://www.fileserve.com/file/4353g9z - my project


The click event only fires for clicks directly on your UserControl itself - not it's children.

To pass clicks from these as well, you need to chain the events:

    public UserControl1()
    {
        InitializeComponent();

        this.pictureBox1.Click += (s,e) => {base.OnClick(e);};
        this.checkBox1.Click += (s,e) => {base.OnClick(e);};
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消