TextBox上实现右键菜单

转载 2007年10月01日 12:31:00

<HTML>
    
<HEAD>
        
<title>TextBoxRightMenu</title>
        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" Content="C#">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        
<STYLE type="text/css">BODY { FONT-SIZE: 9pt }
            TABLE 
{ FONT-SIZE: 9pt; MARGIN: 0px; CURSOR: default }
            TR 
{ HEIGHT: 20px }
            TR.over 
{ FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #000080 }
            TR.out 
{ FONT-SIZE: 9pt; CURSOR: default; COLOR: #000000; BACKGROUND-COLOR: #d4d0c8 }
            DIV.rm_div 
{ BORDER-RIGHT: #ffffff 2px outset; PADDING-RIGHT: 1px; BORDER-TOP: #ffffff 2px outset; DISPLAY: none; PADDING-LEFT: 1px; FILTER: Alpha(Opacity='95'); PADDING-BOTTOM: 1px; BORDER-LEFT: #ffffff 2px outset; WIDTH: 0px; PADDING-TOP: 1px; BORDER-BOTTOM: #ffffff 2px outset; POSITION: absolute; HEIGHT: 0px; BACKGROUND-COLOR: #d4d0c8 }
            DIV.rm_divVisible 
{ BORDER-RIGHT: #ffffff 2px outset; PADDING-RIGHT: 1px; BORDER-TOP: #ffffff 2px outset; PADDING-LEFT: 1px; FILTER: Alpha(Opacity='95'); PADDING-BOTTOM: 1px; BORDER-LEFT: #ffffff 2px outset; WIDTH: 0px; PADDING-TOP: 1px; BORDER-BOTTOM: #ffffff 2px outset; POSITION: absolute; HEIGHT: 0px; BACKGROUND-COLOR: #d4d0c8 }
            HR.sperator 
{ BORDER-RIGHT: #ffffff 1px inset; BORDER-TOP: #ffffff 1px inset; BORDER-LEFT: #ffffff 1px inset; WIDTH: 95%; BORDER-BOTTOM: #ffffff 1px inset }
        
</STYLE>
    
</HEAD>
    
<body MS_POSITIONING="GridLayout" onclick="bodyClick()">
        
<form id="Form1" method="post" runat="server" >
            
<asp:TextBox id="TextBox1" oncontextmenu="PopMenu(this);" style="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
            
<input type="hidden" id="hiddenFontInfo" runat="server" style="WIDTH:10px" NAME="hiddenFontInfo">&nbsp;
            
<input type="hidden" id="hiddenPageIndex" value="0" style="WIDTH:10px">&nbsp;
            
<div id="menuPosition" style="LEFT: 0px;POSITION: absolute;TOP: 0px"></div>
        
</form>
        
<script language="javascript">        
            
function I_OnMouseUp(objtr,objtxt)
            
{
                
var objFont =document.getElementById(objtr.id+'0');
                
if(objFont.id.indexOf('FontSize')>-1)
                    objtxt.style.fontSize 
= objFont.innerHTML+"pt";
                
else if(objFont.id.indexOf('FontFace')>-1)
                    objtxt.style.fontFamily 
= objFont.FontFamily;
                
var objDiv = document.getElementById("menuPosition");
                
if(objDiv !=undefined)
                    objDiv.innerHTML 
="";
            }

            
function I_OnMouseOver(id,parent)
            
{
                 
var Item;
                
if(parent != "rbpm")
                
{
                
var ParentItem;
                ParentItem 
= eval("P_"+parent);
                ParentItem.className
="over";
                }

                Item 
= eval("I_"+id);
                Item.className
="over";
            }

            
function I_OnMouseOut(id)
            
{
                
                
var Item;
                Item 
= eval("I_"+id);
                Item.className
="out";
                
            }

            
var str ="";
            
function PopMenu(obj)
            
{
                
var objID = obj.id;
                window.event.returnValue
=false;
                
                str 
= GetMenuStr(objID);                
                
//debugger;
                var left = parseInt(window.event.clientX,10);
                
var top = parseInt(window.event.clientY,10)+10;//+document.body.scrollTop;
                var objdiv = document.getElementById("menuPosition");
                objdiv.innerHTML 
=str;
                objdiv.style.top 
= top;
                objdiv.style.left 
= left;
                
//
                var ifm = document.createElement("<iframe frameborder=0 marginheight=0 marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>");
                ifm.style.width 
=document.getElementById("E_rbpm").offsetWidth;
                ifm.style.height 
= document.getElementById("E_rbpm").offsetHeight;
                ifm.name 
= ifm.uniqueID;
                objdiv.appendChild(ifm);
            }
            
            
function P_OnMouseOver(id,parent)
            
{
                
var Item;
                
var Extend;
                
var Parent;
                
if(parent != "rbpm")
                
{
                    
var ParentItem;
                    ParentItem 
= eval("P_"+parent);
                    ParentItem.className
="over";
                }

                HideAll(id);
                Item 
= eval("P_"+id);
                Extend 
= eval("E_"+id);
                Parent 
= eval("E_"+parent);
                Item.className
="over";
                Extend.style.display
="block";
                Extend.style.posLeft
=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
                
if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
                    Extend.style.posLeft
=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
                
if(Extend.style.posLeft < 0) Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth;
                Extend.style.posTop
=Parent.offsetTop+Item.offsetTop;
                
if(Extend.style.posTop+Extend.offsetHeight > document.body.scrollTop+document.body.clientHeight)
                    Extend.style.posTop
=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
                
if(Extend.style.posTop < 0
                    Extend.style.posTop
=0;
            }

            
function bodyClick()
            
{
                
var objDiv = document.getElementById("menuPosition");
                
if(objDiv !=undefined)
                    objDiv.innerHTML 
="";
            }

            
function HideAll(id)
            
{
                
if(id=='FontFace')
                
{
                    
var pObj = document.getElementById('P_FontSize');
                    pObj.className 
= 'out';
                    
var childobj = document.getElementById('E_FontSize');
                    childobj.style.display 
= 'none';
                }

                
else if(id=='FontSize')
                
{
                    
var pObj = document.getElementById('P_FontFace');
                    pObj.className 
= 'out';
                    
var childobj = document.getElementById('E_FontFace');
                    childobj.style.display 
= 'none';
                }

            }

            
function P_OnMouseOut(id,parent)
            
{
                
            }

            
function GetMenuStr(objID)
            
{
                
var str1 ="<div class='rm_divVisible' id='E_rbpm' style='POSITION:absolute;z-index:2000;'>"+
                
"<table style='Z-INDEX: 10000' cellSpacing='0' width='100%' border='0'>"+
                
"<tr  class='out' id='P_FontFace' onmouseup='window.event.cancelBubble=true;' onclick='window.event.cancelBubble=true;' onmouseover=/""+"P_OnMouseOver('FontFace','rbpm')/""+"  onmouseout=/""+"P_OnMouseOut('FontFace','rbpm')/""+">"+
                
"<td noWrap align='center'>&nbsp;&nbsp;Font Face&nbsp;&nbsp;</td><td style='FONT-FAMILY: webdings'>4</td>"+
                
"</tr>"+
                
"<tr onmouseup='window.event.cancelBubble=true;' class='out' onclick='window.event.cancelBubble=true;'>"+
                
"<td height='1' colSpan='2'>"+
                
"<hr class='sperator'></td></tr>"+
                
"<tr  class='out' id='P_FontSize' onmouseup='window.event.cancelBubble=true;' onclick='window.event.cancelBubble=true;' onmouseover=/""+"P_OnMouseOver('FontSize','rbpm')/""+"  onmouseout=/""+"P_OnMouseOut('FontSize','rbpm')/""+">"+
                
"<td noWrap align='center'>Font Size</td><td style='FONT-FAMILY: webdings'>4</td>"+
                
"</tr>"+
                
"</table></div>";
                
//
                var str11 ="<div class='rm_div' id='E_FontFace' style='POSITION:absolute;width :140;height:50;Z-INDEX: 2000'>"+
                
"<iframe frameborder=0 marginheight=0 marginwidth=0 hspace=0 vspace=0 scrolling=no style='WIDTH: 100%; HEIGHT: 62%;Z-INDEX: 2000'></iframe>"+
                
"<table width='100%' border='0' cellspacing='0' style='LEFT:0px;POSITION:absolute;TOP:0px'>"+
                
"<tr class='out' id='I_FontFace10' onmouseover=/""+"I_OnMouseOver('FontFace10','FontFace')/""+" onmouseout=/""+"I_OnMouseOut('FontFace10')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontFace100' FontFamily='Tahoma'>Tahoma</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontFace11' onmouseover=/""+"I_OnMouseOver('FontFace11','FontFace')/""+" onmouseout=/""+"I_OnMouseOut('FontFace11')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontFace110' FontFamily='Arial Black'>Arial Black</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontFace12' onmouseover=/""+"I_OnMouseOver('FontFace12','FontFace')/""+" onmouseout=/""+"I_OnMouseOut('FontFace12')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontFace120' FontFamily='Microsoft Sans Serif'>Microsoft Sans Serif</td>"+
                
"</tr>"+
                
"</table></div>";
                
//
                var str12 ="<div class='rm_div' id='E_FontSize' style='POSITION:absolute;width :50;Z-INDEX: 2000'>"+
                
"<iframe frameborder=0 marginheight=0 marginwidth=0 hspace=0 vspace=0 scrolling=no style='WIDTH: 100%; HEIGHT: 109%'></iframe>"+
                
"<table width='100%' border='0' cellspacing='0' style='LEFT:0px;POSITION:absolute;TOP:0px'>"+
                
"<tr class='out' id='I_FontSize10' onmouseover=/""+"I_OnMouseOver('FontSize10','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize10')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize100'>6</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize11' onmouseover=/""+"I_OnMouseOver('FontSize11','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize11')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize110'>7</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize12' onmouseover=/""+"I_OnMouseOver('FontSize12','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize12')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize120'>8</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize13' onmouseover=/""+"I_OnMouseOver('FontSize13','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize13')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize130'>9</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize14' onmouseover=/""+"I_OnMouseOver('FontSize14','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize14')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize140'>10</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize15' onmouseover=/""+"I_OnMouseOver('FontSize15','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize15')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize150'>11</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize16' onmouseover=/""+"I_OnMouseOver('FontSize16','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize16')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize160'>12</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize17' onmouseover=/""+"I_OnMouseOver('FontSize17','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize17')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize170'>13</td>"+
                
"</tr>"+
                
"<tr class='out' id='I_FontSize18' onmouseover=/""+"I_OnMouseOver('FontSize18','FontSize')/""+" onmouseout=/""+"I_OnMouseOut('FontSize18')/""+" onmouseup='I_OnMouseUp(this,"+objID+")'"+" onclick='window.event.cancelBubble=true;'>"+
                
"<td noWrap align='center' id='I_FontSize180'>14</td>"+
                
"</tr>"+
                
"</table></div>";
                
return str1+str11+str12;
            }

        
</script>
    
</body>
</HTML>
 

相关文章推荐

silverlight中添加给TextBox批量添加右键菜单

基于此人写的代码,修改优化后支持批量给所有TextBox添加右键菜单,而菜单共用一个,节省资源。 public static class CreatMenuForTextBox { ...

Flex 实现右键菜单

  • 2014-09-22 11:13
  • 684KB
  • 下载

VC++任务栏托盘图标及右键菜单实现

Windows 95以及后来的Windows版本允许你将程序图标放入系统托盘。所谓系统托盘,通常指的是屏幕右下方显示时间,音量等图标的那个区域。托盘图标通常可以执行一些快捷操作,如窗口隐藏时通常最小化...

右键菜单添加与实现

  • 2013-06-06 18:12
  • 330KB
  • 下载

跨浏览器的网页右键菜单的简单实现

本文主要叙述怎样实现右键菜单,以及跨浏览器的右键菜单的实现。     一般在网页页面按下鼠标右键(这个是在windows平台下,而在MAC中则是CTRL+点击),会显示默认的菜单,要显示自定义的右键菜...

HTML中实现右键菜单功能

  • 2008-04-14 13:08
  • 512KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)