public delegate bool EnumFormInputsProc(IHTMLElement pInputElement, ref object oParam);
/// <summary>
/// Enumerates all input elements in the form by passing the IHTMLElement interface of each input element, in turn, to an application-defined callback function. EnumFormInputs continues until the last input element is enumerated or the callback function returns false.
/// </summary>
/// <remarks>The method cannot retrieve input type=image elements from a form. To access all elements contained in a form, call QueryInterface on IHTMLFormElement and request an IHTMLElement interface. Use the IHTMLElement::children property of the IHTMLElement interface to retrieve a collection of all elements in the form.</remarks>
/// <param name="form">the IHTMLFormElement interface of the form element</param>
/// <param name="enumFormInputsProc">This function is an application-defined callback function that receives input element as a result of a call to the EnumFormInputs function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumFormInputs</param>
/// <returns>true if the last input element is enumerated. otherwise false</returns>
public bool EnumFormInputs(IHTMLFormElement form, EnumFormInputsProc enumFormInputsProc, ref object oParam)
{
for (int i = 0; i < form.length; i++)
{
IHTMLElement pElement = (IHTMLElement)form.item(i, 0);
if (enumFormInputsProc(pElement, ref oParam) == false) return false;
}
return true;
}
/// <summary>
/// Enumerates all input elements in the top level document of the Webbrowser control by passing the IHTMLAnchorElement interface of each anchor element, in turn, to an application-defined callback function. EnumLinks continues until the last anchor element is enumerated or the callback function returns false.
/// </summary>
/// <param name="enumLinkProc">This function is an application-defined callback function that receives anchor element as a result of a call to the EnumLinks function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumLinks</param>
public bool EnumLinks(EnumLinkProc enumLinkProc, ref object oParam)
{
IHTMLDocument2 pDoc = (IHTMLDocument2)this.Document.DomDocument;
return EnumLinks(enumLinkProc, ref oParam, pDoc);
}
/// <summary>
/// Enumerates all input elements in the HTML document by passing the IHTMLAnchorElement interface of each anchor element, in turn, to an application-defined callback function. EnumLinks continues until the last anchor element is enumerated or the callback function returns false.
/// </summary>
/// <param name="enumLinkProc">This function is an application-defined callback function that receives anchor element as a result of a call to the EnumLinks function.</param>
/// <param name="oParam">Specifies the application-defined value given in EnumLinks</param>
/// <param name="pDoc">the IHTMLDocument2 interface of the HTML document</param>
/// <returns>true if the last input element is enumerated. otherwise false</returns>
public bool EnumLinks(EnumLinkProc enumLinkProc, ref object oParam, IHTMLDocument2 pDoc)
{
IHTMLElementCollection anchors=pDoc.links;
if(anchors!=null)
{
int i=0;
for(i=0;i<anchors.length;i++)
{
IHTMLAnchorElement iae = (IHTMLAnchorElement)anchors.item(i, 0);
if (enumLinkProc(iae, ref oParam) == false) return false;
}
}
return true;
}
public bool ScanLinkForHrefProc(IHTMLAnchorElement pAnchorElement, ref object oParam)
{
if (pAnchorElement.href.Contains(oParam.ToString()))
{
oParam = pAnchorElement;
return false;
}
return true;
}
public IHTMLAnchorElement GetLinkByHref(string Text)
{
IHTMLDocument2 pDoc = (IHTMLDocument2)this.Document.DomDocument;
return GetLinkByHref(Text, pDoc);
}
public IHTMLAnchorElement GetLinkByHref(string Text, IHTMLDocument2 pDoc)
{
object oParam=Text;
if (EnumLinks(new EnumLinkProc(ScanLinkForHrefProc)
, ref oParam,pDoc) == false)
{
return (IHTMLAnchorElement)oParam;
}
return null;
}