在MSDN的论坛中看到这段代码, 自己试了一下有效, 记录下来
namespace Sample1
...{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.IsWebBrowserContextMenuEnabled = false;
webBrowser1.WebBrowserShortcutsEnabled = false;
webBrowser1.ObjectForScripting = this;
webBrowser1.DocumentText =
"<html><head><script>" +
"function test(message) { alert(message); }" +
"</script></head><body><button " +
"onclick="window.external.Test('called from script code')">" +
"call client code from script code</button>" +
"</body></html>";
}
public void Test(String message)
...{
Application.Exit();
}
}
}
本文介绍了一段用于配置Windows Forms中WebBrowser控件的C#代码示例。通过该代码可以禁用WebBrowser控件的拖放、上下文菜单及快捷键等功能,并将当前页面设置为一段自定义的HTML内容,其中包括一个按钮,点击后会调用托管代码。
479

被折叠的 条评论
为什么被折叠?



