WebBrowser事件属性?

时间:2009-05-11 15:52:49

标签: c# events webbrowser-control

我能判断一个功能是否已分配给某个事件?

e.g。 (带有Web浏览器控件的标准winforms应用程序)

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...

            }
        }
    }
}

而且,如果我可以像上面描述的那样做,那又怎么样?

1 个答案:

答案 0 :(得分:1)

您可以拨打Deletegate.GetInvocationList

以下是一个例子:

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);
    }   
}