Exemplo n.º 1
0
        public void WrapSelection(string elementName, IDictionary attributes)
        {
            //Create a string for all the attributes
            string attributeString = String.Empty;

            if (attributes != null)
            {
                foreach (string key in attributes.Keys)
                {
                    attributeString += key + "=\"" + attributes[key] + "\" ";
                }
            }
            this.SynchronizeSelection();
            if (this.type == HtmlSelectionType.TextSelection)
            {
                NativeMethods.IHTMLTxtRange textRange = (NativeMethods.IHTMLTxtRange) this.Selection;
                string oldText = textRange.GetHtmlText();
                if (oldText == null)
                {
                    oldText = string.Empty;
                }

                string newText = "<" + elementName + " " + attributeString + ">" + oldText + "</" + elementName + ">";
                textRange.PasteHTML(newText);
            }
        }
Exemplo n.º 2
0
 public void InsertHtml(string html)
 {
     this.Selection.SynchronizeSelection();
     if (this.Selection.Type == HtmlSelectionType.ElementSelection)
     {
         //If it's a control range, we can only insert if we are in a div or td
         NativeMethods.IHtmlControlRange controlRange = (NativeMethods.IHtmlControlRange)Selection.Selection;
         int selectedItemCount = controlRange.GetLength();
         if (selectedItemCount == 1)
         {
             NativeMethods.IHTMLElement element = controlRange.Item(0);
             if ((String.Compare(element.GetTagName(), "div", true) == 0) || (String.Compare(element.GetTagName(), "td", true) == 0))
             {
                 element.InsertAdjacentHTML("beforeEnd", html);
             }
         }
     }
     else
     {
         NativeMethods.IHTMLTxtRange textRange = (NativeMethods.IHTMLTxtRange)Selection.Selection;
         textRange.PasteHTML(html);
     }
 }