質問

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

役に立ちましたか?

解決

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
        }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top