Firing an Event

Hello
I want to fire a custom event from my webbrowser_documentCompleted event.

the webbrowser is held in my Form1 partial class.

Code of documentcompleted event -

                    webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(ScrapeScreen);

                    webBrowser.Navigate(buildURL.ToString());

private void ScrapeScreen(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url.AbsolutePath == (sender as WebBrowser).Url.AbsolutePath)
            {
                if (webBrowser.Document != null)
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(webBrowser.Document.Body.InnerHtml.ToString());

                    int ranking = ScreenScrape.GetScrapeRanking(txtURL.Text, doc);

                    if (ranking > 0)
                    {
                        txtScrapeRanking.Text = ranking.ToString();
                    }
                    else
                    {
                        want to fire my event here!!!!
                    }
                }
            }
        }

Never done custom events so can someone point me to some help.  Thanks.

Kevin
KABarrieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
 else
                    {
                      if(yourCustomEvent != null)
                            yourCustomEvent.Invoke(yourParametersIfAny);
                    }
0
KABarrieAuthor Commented:

Thanks

Can you point me somewhere that shows me how to define the event?

KEv.
0
p_davisCommented:
well can you tell me what parameters you need to pass to the method?

if it there aren't any parameters that are special you can.

public event EventHandler yourCustomEvent;

then with that

yourCustomEvent.Invoke(this, new EventArgs());

otherwise you can make your own delegate handler.

public delegate void customDelegateHandler(yourType yourCustomObject);
public event customDelegateHandler yourCustomEvent;

yourCustomEvent.Inoke(instanceOfYourObjectToPass);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

käµfm³d 👽Commented:
Give the event's handler a signature:

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

Open in new window


Give the event a name and a handler type:

public event YourCustomEventHandler YourCustomEventName

Open in new window


to end up with:

class YourClassName
{
    public delegate void YourCustomEventHandler(object sender, EventArgs e);
    public event YourCustomEventHandler YourCustomEventName

...

}

Open in new window


Then you can handle the event elsewhere like you would any other event:

class SomeOtherClass
{
    public SomeOtherClass()
    {
        YourCustomObject obj = new YourCustomObject();

        obj.YourCustomEvent += new YourCustomEventHandler(My_Handler);
    }

    private void My_Handler(object sender, EventArgs e)
    {
        // Handle event
    }
}

Open in new window

0
käµfm³d 👽Commented:
@p_davis

Sorry. I guess I type too slow  = )
0
p_davisCommented:
not a problem kaufmed -- thanks for the nod
0
KABarrieAuthor Commented:
Thanks guys!
0
KABarrieAuthor Commented:
Thanks Again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.