I am new to C#, I am writing code to open an IEBrowser and do some stuff once its loaded.
If you see the code in Main below
Here is my code :
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
}
}
The IE Window opens up with blank page as needed but the event is never fired up, ofcourse I am doing something wrong as I am super new and probably my first code in C#.
You can make the code simple and try as said below. It is working...
You can notice the document complete event handling.
Look into comments for explanation.
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.