bitcycle
bitcycle

Reputation: 7792

WebBrowser Event Properties?

Can I figure out if a function has already been assigned to an event?

e.g. (Standard winforms app with web browser control)

namespace Crawler {
    public partial class Form1 : Form {

        WebCrawler.manager m;

        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            system.windows.forms.webbrowser wb = new system.windows.forms.webbrowser();
            wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(foo);

            //[... Some other code ...]

            /* [Begin Example] */

            if (wb.DocumentCompleted.Contains(foo){

                // Behave Normally

            }else {

                // Do Something Else...

            }
        }
    }
}

And, if I can do something like I described above, then how?

Upvotes: 1

Views: 453

Answers (1)

Andrew Hare
Andrew Hare

Reputation: 351516

You can call Deletegate.GetInvocationList.

Here is an example:

using System;
using System.Linq;

class Program
{
    static event Action foo;

    static void bar() { }

    static void Main()
    {
        foo += bar;

        bool contains = foo
            .GetInvocationList()
            .Cast<Action>()
            .Contains(bar);
    }   
}

Upvotes: 1

Related Questions