Menu 仅允许在System.Windows.Forms.WebBrowser控件中复制/粘贴上下文菜单
WebBrowser控件有一个名为“IsWebBrowserContextMenuEnabled”的属性,该属性禁用在网页上单击鼠标右键并查看上下文菜单的所有功能。这与我想要的非常接近(我不希望任何人能够右键单击并打印、回击、点击属性、查看源代码等) 唯一的问题是,这也会禁用文本框中显示的用于复制/粘贴等的上下文菜单 更清楚地说,这是我不想要的:Menu 仅允许在System.Windows.Forms.WebBrowser控件中复制/粘贴上下文菜单,menu,browser,contextmenu,Menu,Browser,Contextmenu,WebBrowser控件有一个名为“IsWebBrowserContextMenuEnabled”的属性,该属性禁用在网页上单击鼠标右键并查看上下文菜单的所有功能。这与我想要的非常接近(我不希望任何人能够右键单击并打印、回击、点击属性、查看源代码等) 唯一的问题是,这也会禁用文本框中显示的用于复制/粘贴等的上下文菜单 更清楚地说,这是我不想要的: 这就是我想要的: 我想禁用主上下文菜单,但允许文本框中出现的上下文菜单。有人知道我会怎么做吗?WebBrowser.Document.Contex
这就是我想要的:
我想禁用主上下文菜单,但允许文本框中出现的上下文菜单。有人知道我会怎么做吗?WebBrowser.Document.ContextMenuShow事件看起来很有希望,但似乎无法通过HtmlElementEventArgs参数的“FromElement”和“ToElement”属性正确识别用户右键单击的元素,发送方也只能识别HtmlDocument元素
提前谢谢 您是否考虑过用javascript编写自己的上下文菜单?只需聆听用户右键单击主体,然后使用复制和粘贴命令显示菜单(提示:element.style.display=“block | none”)。要复制,请执行以下代码:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
并粘贴:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Paste");
资料来源:
注意:这只在IE中有效(这对于您的应用程序来说很好)
我知道它无论如何都不是防弹的,但这里有一个代码示例,可以让您开始:
<html>
<head>
<script type = "text/javascript">
var lastForm = null;
window.onload = function(){
var menu = document.getElementById("ContextMenu");
var cpy = document.getElementById("CopyBtn");
var pst = document.getElementById("PasteBtn");
document.body.onmouseup = function(){
if (event.button == 2)
{
menu.style.left = event.clientX + "px";
menu.style.top = event.clientY + "px";
menu.style.display = "block";
return true;
}
menu.style.display = "none";
};
cpy.onclick = function(){
copy = document.selection.createRange();
copy.execCommand("Copy");
return false;
};
pst.onclick = function(){
if (lastForm)
{
copy = lastForm.createTextRange();
copy.execCommand("Paste");
}
return false;
};
};
</script>
</head>
<body oncontextmenu = "return false;">
<div id = "ContextMenu" style = "display : none; background: #fff; border: 1px solid #aaa; position: absolute;
width : 75px;">
<a href = "#" id = "CopyBtn" style = "display: block; color : blue; text-decoration: none;">Copy</a>
<a href = "#" id = "PasteBtn" style = "display: block; color : blue; text-decoration: none;">Paste</a>
</div>
sadgjghdskjghksghkds
<input type = "text" onfocus = "lastForm = this;" />
</body>
</html>
var lastForm=null;
window.onload=函数(){
var menu=document.getElementById(“ContextMenu”);
var cpy=document.getElementById(“CopyBtn”);
var pst=document.getElementById(“粘贴btn”);
document.body.onmouseup=函数(){
如果(event.button==2)
{
menu.style.left=event.clientX+“px”;
menu.style.top=event.clientY+“px”;
menu.style.display=“block”;
返回true;
}
menu.style.display=“无”;
};
cpy.onclick=函数(){
copy=document.selection.createRange();
copy.execCommand(“copy”);
返回false;
};
pst.onclick=函数(){
if(最新表格)
{
copy=lastForm.createTextRange();
copy.execCommand(“粘贴”);
}
返回false;
};
};
SADGGHDSKJGHKSGHKDS
您是否考虑过用javascript编写自己的上下文菜单?只需聆听用户右键单击主体,然后使用复制和粘贴命令显示菜单(提示:element.style.display=“block | none”)。要复制,请执行以下代码:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
并粘贴:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Paste");
资料来源:
注意:这只在IE中有效(这对于您的应用程序来说很好)
我知道它无论如何都不是防弹的,但这里有一个代码示例,可以让您开始:
<html>
<head>
<script type = "text/javascript">
var lastForm = null;
window.onload = function(){
var menu = document.getElementById("ContextMenu");
var cpy = document.getElementById("CopyBtn");
var pst = document.getElementById("PasteBtn");
document.body.onmouseup = function(){
if (event.button == 2)
{
menu.style.left = event.clientX + "px";
menu.style.top = event.clientY + "px";
menu.style.display = "block";
return true;
}
menu.style.display = "none";
};
cpy.onclick = function(){
copy = document.selection.createRange();
copy.execCommand("Copy");
return false;
};
pst.onclick = function(){
if (lastForm)
{
copy = lastForm.createTextRange();
copy.execCommand("Paste");
}
return false;
};
};
</script>
</head>
<body oncontextmenu = "return false;">
<div id = "ContextMenu" style = "display : none; background: #fff; border: 1px solid #aaa; position: absolute;
width : 75px;">
<a href = "#" id = "CopyBtn" style = "display: block; color : blue; text-decoration: none;">Copy</a>
<a href = "#" id = "PasteBtn" style = "display: block; color : blue; text-decoration: none;">Paste</a>
</div>
sadgjghdskjghksghkds
<input type = "text" onfocus = "lastForm = this;" />
</body>
</html>
var lastForm=null;
window.onload=函数(){
var menu=document.getElementById(“ContextMenu”);
var cpy=document.getElementById(“CopyBtn”);
var pst=document.getElementById(“粘贴btn”);
document.body.onmouseup=函数(){
如果(event.button==2)
{
menu.style.left=event.clientX+“px”;
menu.style.top=event.clientY+“px”;
menu.style.display=“block”;
返回true;
}
menu.style.display=“无”;
};
cpy.onclick=函数(){
copy=document.selection.createRange();
copy.execCommand(“copy”);
返回false;
};
pst.onclick=函数(){
if(最新表格)
{
copy=lastForm.createTextRange();
copy.execCommand(“粘贴”);
}
返回false;
};
};
SADGGHDSKJGHKSGHKDS
快速查看显示程序中不支持使用任何鼠标事件(单击、按钮下/上等)。恐怕是要么:要么禁用conetxt菜单,要么允许它们
如果禁用它们,用户仍然可以使用键盘快捷键(Ctrl-C、Ctrl-V)进行复制和粘贴。这可能会为您提供所需的功能。快速查看显示,您的程序中不支持任何鼠标事件(单击、按钮下/上等)。恐怕是要么:要么禁用conetxt菜单,要么允许它们
如果禁用它们,用户仍然可以使用键盘快捷键(Ctrl-C、Ctrl-V)进行复制和粘贴。也许这会为您提供所需的功能。我们最终使用了上述两种注释的组合。更接近第二个,这就是为什么我给了他荣誉
有一种方法可以替换客户端web代码上的上下文菜单,也可以通过winforms替换上下文菜单,这就是我们采用的方法。我真的不想重写上下文菜单,但这似乎为我们提供了正确的控件组合。我们最终使用了上述两种注释的组合。更接近第二个,这就是为什么我给了他荣誉
//Start:
function cutomizedcontextmenu(e)
{
var target = window.event ? window.event.srcElement : e ? e.target : null;
if( navigator.userAgent.toLowerCase().indexOf("msie") != -1 )
{
if (target.type != "text" && target.type != "textarea" && target.type != "password")
{
alert(message);
return false;
}
return true;
}
else if( navigator.product == "Gecko" )
{
alert(message);
return false;
}
}
document.oncontextmenu = cutomizedcontextmenu;
//End:
有一种方法可以替换客户端web代码上的上下文菜单,也可以通过winforms替换上下文菜单,这就是我们采用的方法。