سؤال

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