I am working on an editor using mshtml. I just cannot get cut / copy /
paste to work with ExecCommand. All other command identifiers seem to
be working well. Here is my code:
public partial class Form1 : Form {
private static HtmlDocument htmldoc;
private bool fireonce = false; // fire previewkeydown only once
public Form1( ) {
InitializeComponent( );
}
private void Form1_Load(object sender, EventArgs e) {
webBrowser1.Navigate("about:blank");
webBrowser1.Select( );
}
private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
// the event is always fired twice; likely a .net bug
if ( fireonce ) {
fireonce = false; // prevent firing twice
return;
} // end if
// process key pressed
switch ( e.KeyCode ) {
case Keys.N:
if ( e.Alt ) {
htmldoc.ExecCommand("SelectAll", false, null);
htmldoc.ExecCommand("Italic", false, null);
htmldoc.ExecCommand("Cut", false, null); // does not work
//htmldoc.ExecCommand("Delete", false, null); // works
fireonce =
true; // prevent firing twice
} // end if
break;
} // end switch
return;
}
private void
webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e) {
htmldoc = webBrowser1.Document;
htmldoc.ExecCommand("EditMode", true, null);
}
}
I am using a webBrowser control in the form. When alt-N is pressed, all
texts are selected and turned italic but not cut. If I changed the
"Cut" to a "Delete", all texts can be deleted. "Cut", "Copy" &
"Paste" are not working. Any idea how I can put them to work

using ExecCommand to copy in MSHTML
mobile-fedot
Hope this helps.
Nick__A.
Sirkku Willie MSFT
Does anyone have any idea on this
jeromaqui
This is very helpfull!
paukp06
I wonder what the problem is!!!
Mentz
Keith WIlliams
My test code is like this:
IHTMLDocument2 ihtmldoc2 = (IHTMLDocument2) htmldoc.DomDocument;
IHTMLSelectionObject ihtmlselection = ihtmldoc2.selection;
IHTMLTxtRange range = (IHTMLTxtRange) ihtmlselection.createRange( );
if ( range.queryCommandSupported("Cut") ) {
range.execCommand("Cut", false, null);
MessageBox.Show("Cut is supported");
} // end if
I tried both queryCommandSupported & queryCommandEnabled on ihtmldoc2 & range respectively. The messagebox was shown but the "cut" was not done. This looks really strange.
Alex Aidar
mooremedia
Since the ExecCommand method does not work for some reasons and I found that manually doing ctrl-X ctrl-C ctrl-V works perfectly, may I ask how to programmatically perform the underlying actions of the above control keys. I have tried sendkeys and that does not work either.
Many thanks in advance.
Nuno Castro
CarlMalden
In fact, I have solved the problem already. I was just too lazy to dig back this thread from the forum to post the answer.
I am using XP sp2 and the code works immediately after I removed this registry entry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\ProtocolDefaults]
"about"=dword:00000004
Hope that the info is useful to you & others who come across the same problem.