Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UserControl event

Tags:

c#

winforms

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

like image 919
Nasty Avatar asked Mar 11 '26 22:03

Nasty


1 Answers

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);};
    }
like image 85
John Arlen Avatar answered Mar 14 '26 11:03

John Arlen