This will be helpful if you want to capture only mouse clicks:
WebBrowser _browser;
this._browser.DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
...
private void browser_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
{
this._browser.Document.Body.MouseDown += new HtmlElementEventHandler(Body_MouseDown);
}
...
void Body_MouseDown(Object sender, HtmlElementEventArgs e)
{
switch(e.MouseButtonsPressed)
{
case MouseButtons.Left:
HtmlElement element = this._browser.Document.GetElementFromPoint(e.ClientMousePosition);
if(element != null && "submit".Equals(element.GetAttribute("type"),StringComparison.OrdinalIgnoreCase)
{
}
break;
}
}
can u please tell me how can i read custom attribute of any html
element loaded inside web browser control. thanks
If You don't want to link to "Microsoft.mshtml", You can try to use this sample method. But you can't read all members thru reflection:
public static String GetElementPropertyValue(HtmlElement element, String property)
{
if(element == null)
throw new ArgumentNullException("element");
if(String.IsNullOrEmpty(property))
throw new ArgumentNullException("property");
String result = element.GetAttribute(property);
if(String.IsNullOrEmpty(result))
{//В MSIE 9 получить свойство через DomElement не получается. Т.к. там он ComObject.
var objProperty = element.DomElement.GetType().GetProperty(property);
if(objProperty != null)
{
Object value = objProperty.GetValue(element.DomElement, null);
result = value == null ? String.Empty : value.ToString();
}
}
return result;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…