MSHTML editing - changing the text selection color

236 Views Asked by At

I use MSHTML (TWebBrowser control) in Design (edit) mode. I use TEmbeddedWB but slowly moving away from that component and implementing my own interface. When a block of text is selected, so when typing into the editor and then selecting a block of text it is in black color for the background color.

Instead I'd like to use blue.

I know that it has something to do with the selection range but not sure how to modify it in designer mode. The code below is of course when it is not in design mode.

    IHTMLSelectionObject currentSelection = document.selection;
    IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
    if (range != null)
        {
        range.execCommand("BackColor", false, "0000FF");
        }

Any ideas? Do I have to use event sinking? Or maybe QueryCommandValue? I tried some things with HiliteColor without success yet (according to Mozilla documentation this is not supported by Internet Explorer).

I use C++ Builder or Delphi, but code example in any language is welcome, I can (probably) translate it.

0

There are 0 best solutions below