Hi,
I am working on an editor using the htmldocument in the webbrowser control. This is my code for testing out its capability:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
htmldoc = webBrowser1.Document;
htmldoc.ExecCommand("EditMode", true, null);
}
private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
// process key pressed
switch ( e.KeyCode ) {
case Keys.I:
if ( e.Alt ) {
htmldoc.ExecCommand("Indent", false, null);
} // end if
break;
case Keys.O:
if ( e.Alt ) {
htmldoc.ExecCommand("Outdent", false, null);
} // end if
break;
case Keys.J:
if ( e.Alt ) {
htmldoc.ExecCommand("JustifyRight", false, null);
} // end if
break;
case Keys.K:
if ( e.Alt ) {
htmldoc.ExecCommand("Bold", false, null);
} // end if
break;
case Keys.L:
if ( e.Alt ) {
htmldoc.ExecCommand("Italic", false, null);
} // end if
break;
} // end switch
return;
}
There is only 1 form, in which there is only 1 control, i.e. the
webbrowser control. I am using .Net 2.0. I handle the keys with the
previewkeydown event.
What I do not understand is that the ExecCommand works for Indent /
Outdent / JustifyRight but not for Bold and Italic and also there is no
exception generated. Any idea

simple editor using webBrowser control
Jeffclar
Thanks for you fast replies!
jimadams
TBeaulieu
Nibbla
PJ, any findings at your side I just don't know which is better : your being able to reproduce the case or not.
dbjason
I don't have Visual Studio 2005 here to test, but i have tonight when i am home. But as far as i can see i don't see any problems why it shouldn't work.
brsphere
Hong bo Dai
I am sure I will have further questions for you when I work along with mshtml. There are so much functionality still unexposed to .net !!!
Thank you again for the assistance. It's very much appreciated.
Mirronelli
Though strangely named as PreviewKeyDown, there should be no logical reasons to fire twice. A bug what do you think
It is also strange that I cannot find any mentioning of this in the internet. As this is the only key-event of the webbrowser control, it should be hit easily.
Leo Dragos
Alias2006
There are some default shortcut's, when you press ctrl+b you selected text will get Bold for example. So meybe you can set the shortcut's somewhere, didn't looked to that point.
When you get more strange behaviour or you find a better solution, please let us know!
SanjeevBhatia
stillDesign
I was home very late, i is hard to see nobody else checked it. My excusses, but i will take a look tonight!
Thank you for your patient!
Mihir Vaidya
Here is a little quick-N-dirty solution:
private bool _skipOnce = false;
private void webBrowser1_PreviewKeyDown( object sender, PreviewKeyDownEventArgs e )
{
if( _skipOnce )
{
_skipOnce = false;
return;
}
// process key pressed
switch( e.KeyCode )
{
case Keys.Q:
if( e.Control )
{
htmldoc.ExecCommand( "Bold", false, null );
_skipOnce = true;
}
break;
}
}
igor1960
Many thanks for your assistance in advance.