且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 WebBrowser 控件中使用 Delete 键

更新时间:2023-02-08 15:11:00

问题是控件属性之一,WebBrowserShortcutsEnabled"被设置为 false.感谢大家的帮助,没有人能猜到这一点,所以我得到了一个大大的DUH!".我确实找到了一种在 c# 中完成这项工作的方法,其中代码如下所示:

Well the problem was that one of the control properties, "WebBrowserShortcutsEnabled" was set to false. Thanks everyone for your help, there is no way anyone could have guessed that so I get a big "DUH!". I did find a way to make this work in c# where the code would look like this:

public Form1() {
    InitializeComponent();
    webBrowser1.Navigate("about:blank");  // Initializes the webbrowser control
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
    mshtml.IHTMLDocument2 doc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
    doc.designMode = "On";
    webBrowser1.Document.OpenNew(false).Write(@"<html><body><span>Project Title</span><input type=""text"" value="""" /></body></html>");
}

...假设引用已添加到 MSHTML.documentCompleted 事件与我的第一个代码示例中的 Application.DoEvents 完成相同的事情,因此可以采用任何一种方式.

...assuming that a reference had been added to MSHTML. The documentCompleted event accomplishes the same thing as the Application.DoEvents in my first code exmaple, so that could go either way.