Click event for .Net (Windows Forms) user control

前端 未结 2 1278
予麋鹿
予麋鹿 2020-12-06 19:55

This is probably a very simple question, but for some reason, even the right way to web search for the answer eludes me...

I\'m trying to create a user control that

相关标签:
2条回答
  • 2020-12-06 20:55

    I've never tried this with Windows Forms, but in other GUIs I've placed a transparent panel that covers the entire form so that when you click "on the form," the event actually goes to the panel control.

    0 讨论(0)
  • 2020-12-06 20:56

    Sorry about this - just putting an answer on in case someone googles it...

    In case you're interested, this post helped solve it: User Control Click - Windows Forms… Basically, remove HandleClick, and the property and substitute this one instead:

    public new event EventHandler Click
    {
        add
        {
            base.Click += value;
            foreach (Control control in Controls)
            {
                control.Click += value;
            }
        }
        remove
        {
            base.Click -= value;
            foreach (Control control in Controls)
            { 
                control.Click -= value;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题