Domanda

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

È stato utile?

Soluzione

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
        }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top