When using the ie WebBrowser control in. net, you need to customize component events and styles according to your own needs. In fact, it is very easy to control ie components in. net, and all the functions provided by MSHTML can be used. You can intercept all operation events of a user and obtain the object attributes of the user operation. Below is my reserved code for future use.
# Event triggering definition required by region WebBrowser
///
/// Generic html dom Event method handler.
///
Public delegate void DHTMLEvent (IHTMLEventObj e );
///
/// Generic Event handler for html dom objects.
/// Handles a basic event object which has es an IHTMLEventObj which
/// Applies to all document events raised.
///
Public class DHTMLEventHandler
{
Public DHTMLEvent Handler;
HTMLDocument Document;
Public DHTMLEventHandler (HTMLDocument doc)
{
This. Document = doc;
}
[DispId (0)]
Public void Call ()
{
Handler (Document. parentWindow. @ event );
}
}
# Endregion
Private void axWebBrowserADS_DocumentComplete (object sender, AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent e)
{
HTMLDocument doc = this. axWebBrowserADS. Document as HTMLDocument;
// Bind events
DHTMLEventHandler onclickHandler = new DHTMLEventHandler (doc );
OnclickHandler. Handler + = new DHTMLEvent (this. myads_onclick );
Doc. onclick = onclickHandler;
DHTMLEventHandler contextMenuHandler = new DHTMLEventHandler (doc );
ContextMenuHandler. Handler + = new DHTMLEvent (this. myads_oncontextmenu );
Doc. oncontextmenu = contextMenuHandler;
DHTMLEventHandler onkeydownHandler = new DHTMLEventHandler (doc );
OnkeydownHandler. Handler + = new DHTMLEvent (this. myads_onkeydown );
Doc. onkeydown = onkeydownHandler;
Doc. body. style. border = "none ";
Doc. body. style. overflow = "hidden ";
}
Private void myads_oncontextmenu (IHTMLEventObj pEvtObj)
{
PEvtObj. returnValue = false;
}
Private void myads_onclick (IHTMLEventObj pEvtObj)
{
String a = pEvtObj. srcElement. GetType (). ToString ();
If (a = "mshtml. HTMLAnchorElementClass ")
{
Mshtml. HTMLAnchorElementClass link = (mshtml. HTMLAnchorElementClass) pEvtObj. srcElement;
If (link. href. Substring (0, 5). ToUpper () = "JOIN :")
{
ClsVariable. FM_SERVICESLIST.doJOINcmd (link. href. Substring (5 ));
PEvtObj. returnValue = false;
}
Else if (link. id. Substring (0, 1) = "#")
{
ClsVariable. FM_SERVICESLIST.doJOINcmd (link. id );
PEvtObj. returnValue = false;
}
Else
{
Link.tar get = "_ blank ";
}
}
Else if (a = "mshtml. HTMLImgClass ")
{
Mshtml. HTMLImgClass img = (mshtml. HTMLImgClass) pEvtObj. srcElement;
If (img. id! = Null & img. id. Substring (0, 1) = "#")
{
ClsVariable. FM_SERVICESLIST.doJOINcmd (img. id );
PEvtObj. returnValue = false;
}
Else
{
Mshtml. HTMLAnchorElementClass link = (mshtml. HTMLAnchorElementClass) pEvtObj. srcElement;
If (link! = Null)
Link.tar get = "_ blank ";
}
}
Else if (a = "mshtml. HTMLAreaElementClass ")
{
Mshtml. HTMLAreaElementClass area = (mshtml. HTMLAreaElementClass) pEvtObj. srcElement;
If (area. href. Substring (0, 5). ToUpper () = "JOIN :")
{
ClsVariable. FM_SERVICESLIST.doJOINcmd (area. href. Substring (5 ));
PEvtObj. returnValue = false;
}
Else if (area. id! = Null & area. id. Substring (0, 1) = "#")
{
ClsVariable. FM_SERVICESLIST.doJOINcmd (area. id );
PEvtObj. returnValue = false;
}
Else
{
Area.tar get = "_ blank ";
}
}
}
Private void myads_onkeydown (IHTMLEventObj pEvtObj)
{
If (pEvtObj. keyCode = 8) // backspace
{
PEvtObj. keyCode = 0;
PEvtObj. returnValue = false;
}
Else if (pEvtObj. keyCode = 116) // KEY F5
{
PEvtObj. keyCode = 0;
PEvtObj. returnValue = false;
}
Else if (pEvtObj. ctrlKey & pEvtObj. keyCode = 70) // Key ctrl + F
{
PEvtObj. keyCode = 0;
PEvtObj. returnValue = false;
}
Else if (pEvtObj. ctrlKey & pEvtObj. keyCode = 78) // Key ctrl + N
{
PEvtObj. keyCode = 0;
PEvtObj. returnValue = false;
}
Else if (pEvtObj. ctrlKey & pEvtObj. keyCode = 80) // Key ctrl + P
{
PEvtObj. keyCode = 0;
PEvtObj. returnValue = false;
}
}