Frage

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

War es hilfreich?

Lösung

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
        }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top