Exemplo n.º 1
0
        //</SNIPPET3>

        //<SNIPPET4>
        private void CreateHyperlinkFromSelection()
        {
            if (webBrowser1.Document != null)
            {
                mshtml.IHTMLDocument2 iDoc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;

                if (iDoc != null)
                {
                    mshtml.IHTMLSelectionObject iSelect = iDoc.selection;
                    if (iSelect == null)
                    {
                        MessageBox.Show("Please select some text before using this command.");
                        return;
                    }

                    mshtml.IHTMLTxtRange txtRange = (mshtml.IHTMLTxtRange)iSelect.createRange();

                    // Create the link.
                    if (txtRange.queryCommandEnabled("CreateLink"))
                    {
                        Object o = null;
                        txtRange.execCommand("CreateLink", true, o);
                    }
                }
            }
        }
        /// <summary>
        /// Determines the value of the command
        /// </summary>
        private object QueryCommandRange(mshtmlTextRange range, string command)
        {
            object retValue = null;
            if (range != null)
            {
                try
                {
                    // ensure command is a valid command and then enabled for the selection
                    if (range.queryCommandSupported(command))
                    {
                        if (range.queryCommandEnabled(command))
                        {
                            retValue = range.queryCommandValue(command);
                        }
                    }
                }
                catch (Exception)
                {
                    // have unknown error so set return to null
                    retValue = null;
                }
            }

            // return the obtained value
            return retValue;
        }
 /// <summary>
 /// Executes the execCommand on the selected range (given the range)
 /// </summary>
 private void ExecuteCommandRange(mshtmlTextRange range, string command, object data)
 {
     try
     {
         if (range != null)
         {
             // ensure command is a valid command and then enabled for the selection
             if (range.queryCommandSupported(command))
             {
                 if (range.queryCommandEnabled(command))
                 {
                     // mark the selection with the appropriate tag
                     range.execCommand(command, false, data);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         // Unknown error so inform user
         throw new HtmlEditorException("Unknown MSHTML Error.", command, ex);
     }
 }
        /// <summary>
        /// Executes the queryCommandState on the selected range (given the range)
        /// </summary>
        private bool ExecuteCommandQuery(mshtmlTextRange range, string command)
        {
            // set the initial state as false
            bool retValue = false;

            try
            {
                if (range != null)
                {
                    // ensure command is a valid command and then enabled for the selection
                    if (range.queryCommandSupported(command))
                    {
                        if (range.queryCommandEnabled(command))
                        {
                            // mark the selection with the appropriate tag
                            retValue = range.queryCommandState(command);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Unknown error so inform user
                throw new HtmlEditorException("Unknown MSHTML Error.", command, ex);
            }

            // return the value
            return retValue;
        }
Exemplo n.º 5
0
        } // QueryCommandRange

        /// <summary>
        /// Determines the value of the command
        /// </summary>
        private object QueryCommandRange(mshtmlTextRange range, string command)
        {
            object retValue = null;
            try
            {
                if (!range.IsNull() && !range.text.IsNullOrEmpty())
                {
                    // ensure command is a valid command and then enabled for the selection
                    if (range.queryCommandSupported(command))
                    {
                        if (range.queryCommandEnabled(command))
                        {
                            retValue = range.queryCommandValue(command);
                        }
                    }
                }
                else
                {
                    retValue = QueryCommandDocument(command);
                }
            }
            catch (Exception)
            {
                // have unknown error so set return to null
                retValue = null;
            }
            // return the obtained value
            return retValue;

        } //QueryCommandRange