Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# InternetExplorer DocumentCompleteEventHandler未在C中启动#_C#_C# 4.0 - Fatal编程技术网

C# InternetExplorer DocumentCompleteEventHandler未在C中启动#

C# InternetExplorer DocumentCompleteEventHandler未在C中启动#,c#,c#-4.0,C#,C# 4.0,我是C#新手,我正在编写代码来打开IEBrowser,并在加载后执行一些操作 如果您在下面的Main中看到代码 这是我的密码: public delegate void DocumentCompleteEventHandler(SHDocVw.InternetExplorer IE); class Program{ private static string m_autoLoginFormContents = null; private static SHDocVw.Intern

我是C#新手,我正在编写代码来打开IEBrowser,并在加载后执行一些操作

如果您在下面的Main中看到代码

这是我的密码:

public delegate void DocumentCompleteEventHandler(SHDocVw.InternetExplorer IE);
class Program{
    private static string m_autoLoginFormContents = null;
    private static SHDocVw.InternetExplorer m_autologinIEWindow;
    static SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler m_AutoLoginDocCompleteHandler;
    private static SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler m_documentCompleteEventHandler;
    public static event DocumentCompleteEventHandler DocumentComplete;

    static void Main(string[] args)
    {
        m_documentCompleteEventHandler = new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(DocumentCompleteEventHandler);
        m_autologinIEWindow = OpenIEWindowToURL("about:blank");
        m_autologinIEWindow.DocumentComplete += m_AutoLoginDocCompleteHandler;
        m_AutoLoginDocCompleteHandler = new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(URLAutologinDocumentCompleteEventHandler);

        System.Console.Read();
    }

    public static void URLAutologinDocumentCompleteEventHandler(object senderObject, ref object objectTwo /* not sure what this argument is for */)
    {
        //Something
    }

    private static void DocumentCompleteEventHandler(object senderObject, ref object objectTwo /* not sure what this argument is for */ )
    {
           //Something
    }
}

IE窗口会根据需要打开空白页面,但事件从未启动,当然,我做了一些错误的事情,因为我是超级新的,可能是我在C#中的第一个代码。

您可以简化代码,然后按照下面所述进行尝试。它正在工作

您可以注意到文档完成了事件处理

查看评论以获得解释

    static void Main()
    {

        //DECLARE INTERNET EXPLORER OBJECT
        SHDocVw.InternetExplorer m_autologinIEWindow = new SHDocVw.InternetExplorer();

        //ASSOCIATE HANDLER TO DOCUMENT COMPLETE EVENT
        m_autologinIEWindow.DocumentComplete += URLAutologinDocumentCompleteEventHandler;

        //NAVIGATE THE URL
        m_autologinIEWindow.Navigate("about:blank");
        m_autologinIEWindow.AddressBar = true;
        m_autologinIEWindow.Visible = true;

    }

    //HANDLER DEFINITION
    public static void URLAutologinDocumentCompleteEventHandler(object senderObject, ref object objectTwo /* not sure what this argument is for */)
    {
        //Something
    }

您可以简化代码并尝试如下所述。它正在工作

您可以注意到文档完成了事件处理

查看评论以获得解释

    static void Main()
    {

        //DECLARE INTERNET EXPLORER OBJECT
        SHDocVw.InternetExplorer m_autologinIEWindow = new SHDocVw.InternetExplorer();

        //ASSOCIATE HANDLER TO DOCUMENT COMPLETE EVENT
        m_autologinIEWindow.DocumentComplete += URLAutologinDocumentCompleteEventHandler;

        //NAVIGATE THE URL
        m_autologinIEWindow.Navigate("about:blank");
        m_autologinIEWindow.AddressBar = true;
        m_autologinIEWindow.Visible = true;

    }

    //HANDLER DEFINITION
    public static void URLAutologinDocumentCompleteEventHandler(object senderObject, ref object objectTwo /* not sure what this argument is for */)
    {
        //Something
    }