views:

21

answers:

1

Hi All

This might be abit "out there", but here goes:

I have a User Control. And I have a project. How can I have my user control pass a particular "event" to my project, and then have my project run that event?

+1  A: 

In your UserControl

        public delegate void BigEventHandler(object sender, EventArgs e);

        public event BigEventHandler SomeThingBigHappened;


        private void button1_Click(object sender, EventArgs e)
        {
            OnSomeThingBigHappened(e);
        }

        protected virtual void OnSomeThingBigHappened(EventArgs e)
        {
            SomeThingBigHappened(this, e);
        }

In your form

 private void userControl11_SomeThingBigHappened(object sender, EventArgs e)
        {
            MessageBox.Show("Something Really Really big happened in Usercontrol!!");
        }

You will need to bind the usercontrol event in form designer, and in control, instead of button1_click, make the OnSomeThingBigHappened(e);call where the event will occur

Midhat
Oh, that's perfect! I thought it was a stupid question and that it couldn't be done.
lucifer
Thank you :)...
lucifer
glad 2b of any help
Midhat