Question

I create a custom user control and use that in my form.

but it does not capture any mouse event! what is the problem? thanks

Was it helpful?

Solution

Define the event in your custom control

private delegate void MyClickEvent(object sender, EventArgs e); 
public event MyClickEvent MyClick; 


public void OnMyClickEvent(object sender, EventArgs e)
        {
                if (MyClick != null)
                        MyClick(sender, e);//execute event
        } 

Now in MainForm

public partial class Form1
{
        public Form1()
        {
                myCustomButton.MyClick += FireThisOnClick;
        }

        private void FireThisOnClick(object sender, EventArgs e)
        {
                //this will be executed on click
        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top