WebBrowser Event Properties?

橙三吉。 提交于 2019-12-08 06:46:21

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/848757/webbrowser-event-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!