/// <summary> /// Executes the execCommand on the selected range (given the range) /// </summary> private void ExecuteCommandRange(mshtmlTextRange range, string command, object data) { try { if (!range.IsNull()) { // 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, bool isEnabled = false) { // set the initial state as false bool retValue = false; try { if (!range.IsNull()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (isEnabled) { retValue = range.queryCommandEnabled(command); } else { 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; }