如何在 WebBrowser 控件中使用 Delete 键 [英] How do I make the Delete key work in the WebBrowser control

查看:45
本文介绍了如何在 WebBrowser 控件中使用 Delete 键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .net Windows 窗体项目,其中包括 System.Windows.forms.WebBrowser 控件,以允许用户对 HTML 内容进行一些编辑.当此控件处于编辑模式时,可以对 div 或 span 等元素进行拖放编辑,但选择一个元素并键入 Delete 什么也不做.

I have a .net Windows forms project that includes the System.Windows.forms.WebBrowser control to allow the user to do some editing of HTML content. When this control is in edit mode Elements such as div or span can be drag-and-drop edited, but selecting an element and typing Delete does nothing.

我看过一些帖子,讨论在 C++ 中实现这项工作,但它们不是很详细.示例 http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/1f485dc6-e8b2-4da7-983f-ca431f96021f/

I have seen a few posts that talk about making this work in C++ but they are not very detailed. Example http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/1f485dc6-e8b2-4da7-983f-ca431f96021f/

下一篇文章将讨论使用名为 TranslateAccelerator 方法的函数来解决 MFC 项目中的类似问题.http://vbyte.com/iReader/Reader.asp?ISBN=0735607818&URI=/HTML/chaab.htm

This next post talks about using a function called TranslateAccelerator method to solve similar problems in MFC projects. http://vbyte.com/iReader/Reader.asp?ISBN=0735607818&URI=/HTML/chaab.htm

有没有人有关于如何在 C# 或 VB 中为 Windows 窗体项目使用删除键的建议?

Does anyone have a suggestion on how to make the delete key work in C# or VB for a windows forms project?

这是我创建 WebBrowser 内容的代码:

Here is my code to create the WebBrowser content:

WebBrowser1.Navigate("about:blank")   ' Initializes the control
Application.DoEvents
WebBrowser1.Document.OpenNew(False).Write("<html><body><span>Project Title</span><input type='text' value='' /></body></html>")
WebBrowser1.ActiveXInstance.Document.DesignMode = "On"  ' Option Explicit must be set to off
WebBrowser1.Document.Body.SetAttribute("contenteditable", "true")

谢谢

推荐答案

问题是控件属性之一,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.

这篇关于如何在 WebBrowser 控件中使用 Delete 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆