本文整理汇总了C#中IHTMLDocument2.createElement方法的典型用法代码示例。如果您正苦于以下问题:C# IHTMLDocument2.createElement方法的具体用法?C# IHTMLDocument2.createElement怎么用?C# IHTMLDocument2.createElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHTMLDocument2
的用法示例。
在下文中一共展示了IHTMLDocument2.createElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddEmbeddedCSS
/// <summary>
/// This embeds an inline css stylesheet that allows tags
/// in the users guide html that are in the class "hideonline"
/// to be hidden in the version poseted to the website
/// </summary>
/// <param name="htmlDoc"></param>
private static void AddEmbeddedCSS( IHTMLDocument2 htmlDoc )
{
IHTMLStyleElement style = htmlDoc.createElement( "style" ) as IHTMLStyleElement;
style.type = "text/css";
style.styleSheet.cssText = ".hideonline{ display:none; }";
IHTMLElementCollection collection = htmlDoc.all.tags( "head" ) as IHTMLElementCollection;
Debug.Assert( collection != null );
Debug.Assert( collection.length == 1 );
mshtml.IHTMLDOMNode head = collection.item( 0, 0 ) as IHTMLDOMNode;
Debug.Assert( head != null );
head.appendChild( style as IHTMLDOMNode );
}
示例2: OnDocCompleted
private static void OnDocCompleted(int procId, IHTMLDocument2 doc)
{
Console.WriteLine(procId.ToString() + ") OnDocCompleted called [Doc:" + doc.ToString() + "]");
//on document completion add our custom DIV
//create sample element
IHTMLElement elem = doc.createElement("div");
elem.innerHTML = "Hello from RemoteCOM";
elem.setAttribute("id", "RemoteCOM_SampleDiv", 0);
//style it
IHTMLStyle2 style2 = elem.style as IHTMLStyle2;
style2.right = 0;
elem.style.top = 0;
style2.position = "absolute";
elem.style.border = "2px solid #FFFF00";
elem.style.background = "#FFFFC0";
elem.style.zIndex = 10000;
elem.style.font = "bold 12px Helvetica";
elem.style.padding = "5px";
//insert new element into body
IHTMLDOMNode bodyNode = doc.body as IHTMLDOMNode;
IHTMLDOMNode elemNode = elem as IHTMLDOMNode;
bodyNode.appendChild(elemNode);
//remember to force release com objects
Marshal.ReleaseComObject(elem);
Marshal.ReleaseComObject(style2);
Marshal.ReleaseComObject(elemNode);
Marshal.ReleaseComObject(bodyNode);
return;
}
示例3: AddNewElementToContainer
/// <summary>
/// Add a new element of the specified type to the specified container
/// </summary>
/// <param name="elementName"></param>
/// <param name="htmlDocument"></param>
/// <param name="container"></param>
/// <returns></returns>
static public IHTMLElement AddNewElementToContainer(string elementName, IHTMLDocument2 htmlDocument, IHTMLElement container)
{
IHTMLElement newElement = htmlDocument.createElement(elementName);
((IHTMLDOMNode)container).appendChild((IHTMLDOMNode)newElement);
return newElement;
}