散分!!!WinForm的菜单问题!! 应该使用PopupMenu,弹出的位置就是鼠标位置 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以先记下menu(类似于Windows的开始菜单的东西)弹出的位置,px,py。再根据鼠标右键单击的位置e.x和e.y计算菜单项的位置(e.x-px,e.y-py),再根据(e.x-px,e.y-py)确定是点击了那个菜单项,然后popmenu, 看看JAVASCRIPT的一个例子<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><meta name="ProgId" content="FrontPage.Editor.Document"><title>伟COOL网</title><script language="javascript"><script language="JavaScript"><!-- function initInteractions(){} //--></script><script language="javascript"> var intDelay=50; //设置菜单显示速度,越大越慢 var intInterval=5; //每次更改的透明度 function MenuClick() { if (LayerMenu.style.display=="") { GradientClose(); } else{ LayerMenu.filters.alpha.opacity=0; LayerMenu.style.display=""; GradientShow(); } } function GradientShow() //实现淡入的函数 { LayerMenu.filters.alpha.opacity+=intInterval; if (LayerMenu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay); } function GradientClose() //实现淡出的函数 { LayerMenu.filters.alpha.opacity-=intInterval; if (LayerMenu.filters.alpha.opacity>0) { setTimeout("GradientClose()",intDelay); } else { LayerMenu.style.display="none"; } } function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的 { oEl=event.srcElement; if (oEl.style.background!="navy") { oEl.style.background="navy"; } else { oEl.style.background="#cccccc"; } } function ItemClick() //在菜单项上单击后打开相应链接 { oEl=event.srcElement; oLink=oEl.all.tags( "A" ); if( oLink.length ) { oLink[0].click(); GradientClose(); } }</script> <style> .up{BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #666666 1px solid;font-size:9pt;cursor=default} .down{BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #ffffff 1px solid;font-size:9pt;cursor=default} .c { font-size: 9pt; cursor: default}.h { font-size: 9pt; color: #FFFFFF; cursor: default} </style>//以上定义CSS</head><body><div style="Position:Absolute;Left:200px;Top:256px;width:334px; height:21px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000"><table border=0 cellpadding=0 cellspacing=0 width=516 height="21"><tr><script language="JavaScript"> function A() { if (LayerMenu.style.display=="") { event.srcElement.className='up'; } else{ event.srcElement.className='down'; } }</script><td width="56"><img id=b class=up onmousedown="A()" onselectstart="return false;" onclick="MenuClick()" src="http://weicool.myrice.com/vku_logo.gif" width="56" height="21" align="absmiddle"></td> <td class=up onclick="GradientClose();"><div align="center">模拟 windows 2000 淡入淡出菜单 —— 伟COOL网络</div></td></tr></table></div>//以上为按钮层 <div class=up id=LayerMenu style="Position:Absolute;Left:200px;Top:155px;Display:none;filter:alpha(opacity=0);width: 169px; height: 83px" oncontextmenu="return false" onMouseover="window.event.cancelBubble = true;"><table border=0 cellpadding=0 cellspacing=0 bgcolor=#CCCCCC width="100%"><tr><td width=20 valign=bottom bgcolor=navy></td><td><table border=0 width=100% cellpadding=0 cellspacing=0 onselectstart="return false;" onClick="ItemClick();" onMouseOver="ChangeBG();" onMouseOut="ChangeBG();"><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> ascii图形(T)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 教程下载(D)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 素材库(G)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 请您留言(S)</td></tr></table></td></tr></table></div>//菜单层<div id="body" style="position:absolute; width:938px; height:903px; top: 77px; left: 25px" onmousedown="b.className='up'" onclick="GradientClose();"></div>目的是鼠标单击外面时菜单淡入</body></html> <html><head><title>Fenghua Lu</title><script language="javascript"><script language="JavaScript"><!-- function initInteractions(){} //--></script><script language="javascript"> var intDelay=50; //设置菜单显示速度,越大越慢 var intInterval=5; //每次更改的透明度 function MenuClick() { if (LayerMenu.style.display=="") { GradientClose(); } else{ LayerMenu.filters.alpha.opacity=0; LayerMenu.style.display=""; GradientShow(); } } function GradientShow() //实现淡入的函数 { LayerMenu.filters.alpha.opacity+=intInterval; if (LayerMenu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay); } function GradientClose() //实现淡出的函数 { LayerMenu.filters.alpha.opacity-=intInterval; if (LayerMenu.filters.alpha.opacity>0) { setTimeout("GradientClose()",intDelay); } else { LayerMenu.style.display="none"; } } function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的 { oEl=event.srcElement; if (oEl.style.background!="navy") { oEl.style.background="navy"; } else { oEl.style.background="#cccccc"; } } function ItemClick() //在菜单项上单击后打开相应链接 { oEl=event.srcElement; oLink=oEl.all.tags( "A" ); if( oLink.length ) { oLink[0].click(); GradientClose(); } }</script> <style> .up{BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #666666 1px solid;font-size:9pt;cursor=default} .down{BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #ffffff 1px solid;font-size:9pt;cursor=default} .c { font-size: 9pt; cursor: default}.h { font-size: 9pt; color: #FFFFFF; cursor: default} </style> <!--//以上定义CSS--></head><body><div style="Position:Absolute;Left:200px;Top:256px;width:334px; height:21px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000"><table border=0 cellpadding=0 cellspacing=0 width=516 height="21"><tr><script language="JavaScript"> function A() { if (LayerMenu.style.display=="") { event.srcElement.className='up'; } else{ event.srcElement.className='down'; } }</script><td width="56"><img id=b class=up onmousedown="A()" onselectstart="return false;" onclick="MenuClick()" src="http://www.1000script.com/pic/win.gif" width="56" height="21" align="absmiddle"></td> <td class=up onclick="GradientClose();"><div align="center">人大附中选修课管理系统</div></td></tr></table></div> <!--//以上为按钮层--><div class=up id=LayerMenu style="Position:Absolute;Left:200px;Top:155px;Display:none;filter:alpha(opacity=0);width: 169px; height: 83px" oncontextmenu="return false" onMouseover="window.event.cancelBubble = true;"><table border=0 cellpadding=0 cellspacing=0 bgcolor=#CCCCCC width="100%"><tr><td width=20 valign=bottom bgcolor=navy></td><td><table border=0 width=100% cellpadding=0 cellspacing=0 onselectstart="return false;" onClick="ItemClick();" onMouseOver="ChangeBG();" onMouseOut="ChangeBG();"><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>教师入口(T)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>学生入口(D)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>管理员入口(G)</td></tr><tr><td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>浏览检索(S)</td></tr></table></td></tr></table></div> <!--//菜单层--><div id="body" style="position:absolute; width:938px; height:903px; top: 77px; left: 25px" onmousedown="b.className='up'" onclick="GradientClose();"></div> <!--目的是鼠标单击外面时菜单淡入--></body></html> 这个问题我记得在http://www.csdn.net/magazine中有看到过,很有意思啊,UPps:上面那个JS(网页)这么弱智有什么好贴的? 谢谢各位斑竹帮我置了顶!!!Thank you!!! 你是要WinFOrm的还是WEB 的啊?? 换个思维,我已前在Delphi中用窗口替代菜单,每一个用一个Panel,C#中没有试过。这个可能有帮助:http://www.codeproject.com/cs/menu/vsnetmenu.asp免费注册后,才能宰 小弟现在刚学C#,不会(希望大家能提供几本C#好书)以前在VB里写过,用小窗体代替菜单,在窗体上用MSFlexGrid连着数据库(同时用了各种图标) 请问,进度条控件 webbrowser中的DocumentCompleted事件,同一链接第2次打开时不被触发,跟缓存有关吗? C#事物的回滚问题 C# 看一下byte[]创建空字节串没有长度限制的问题。 关于隐藏父类方法的疑惑 123456 加密后 密文是 Nqo(&FZV|ixr 加密方法用C#怎么写 各位:帮忙看一下哪里有"时间掩码控件"! 如何用DataSet生成指定结构的XML?? 如何实现下载?请求帮忙 我公司(在深圳)現想請.net高手來講課,請有意的朋友留下msn號,我們會和您聯繫. MSDN 2003 April 中有什么内容,值得下载吗? 在程序中调用外部命令.
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>伟COOL网</title><script language="javascript">
<script language="JavaScript"><!--
function initInteractions(){}
//--></script><script language="javascript">
var intDelay=50; //设置菜单显示速度,越大越慢
var intInterval=5; //每次更改的透明度
function MenuClick()
{
if (LayerMenu.style.display=="")
{
GradientClose();
}
else{
LayerMenu.filters.alpha.opacity=0;
LayerMenu.style.display="";
GradientShow();
}
} function GradientShow() //实现淡入的函数
{
LayerMenu.filters.alpha.opacity+=intInterval;
if (LayerMenu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay);
}
function GradientClose() //实现淡出的函数
{
LayerMenu.filters.alpha.opacity-=intInterval;
if (LayerMenu.filters.alpha.opacity>0) {
setTimeout("GradientClose()",intDelay);
}
else {
LayerMenu.style.display="none";
}
}
function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的
{
oEl=event.srcElement;
if (oEl.style.background!="navy") {
oEl.style.background="navy";
}
else {
oEl.style.background="#cccccc";
}
}
function ItemClick() //在菜单项上单击后打开相应链接
{
oEl=event.srcElement;
oLink=oEl.all.tags( "A" );
if( oLink.length )
{
oLink[0].click();
GradientClose();
}
}</script>
<style>
.up{BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #666666 1px solid;font-size:9pt;cursor=default}
.down{BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #666666 1px solid;
BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #ffffff 1px solid;font-size:9pt;cursor=default}
.c { font-size: 9pt; cursor: default}.h { font-size: 9pt; color: #FFFFFF;
cursor: default}
</style>//以上定义CSS</head><body><div style="Position:Absolute;Left:200px;Top:256px;width:334px; height:21px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000">
<table border=0 cellpadding=0 cellspacing=0 width=516 height="21">
<tr><script language="JavaScript">
function A()
{
if (LayerMenu.style.display=="")
{
event.srcElement.className='up';
}
else{
event.srcElement.className='down';
}
}</script>
<td width="56"><img id=b class=up onmousedown="A()" onselectstart="return false;" onclick="MenuClick()" src="http://weicool.myrice.com/vku_logo.gif" width="56" height="21" align="absmiddle"></td>
<td class=up onclick="GradientClose();">
<div align="center">模拟 windows 2000 淡入淡出菜单 —— 伟COOL网络</div>
</td></tr></table></div>//以上为按钮层
<div class=up id=LayerMenu style="Position:Absolute;Left:200px;Top:155px;Display:none;filter:alpha(opacity=0);width: 169px; height: 83px" oncontextmenu="return false" onMouseover="window.event.cancelBubble = true;">
<table border=0 cellpadding=0 cellspacing=0 bgcolor=#CCCCCC width="100%">
<tr><td width=20 valign=bottom bgcolor=navy></td><td>
<table border=0 width=100% cellpadding=0 cellspacing=0 onselectstart="return false;" onClick="ItemClick();" onMouseOver="ChangeBG();" onMouseOut="ChangeBG();">
<tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> ascii图形(T)</td></tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 教程下载(D)</td></tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 素材库(G)</td>
</tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a> 请您留言(S)</td></tr></table></td></tr>
</table></div>//菜单层<div id="body" style="position:absolute; width:938px; height:903px; top: 77px; left: 25px" onmousedown="b.className='up'" onclick="GradientClose();"></div>目的是鼠标单击外面时菜单淡入</body></html>
<head>
<title>Fenghua Lu</title><script language="javascript">
<script language="JavaScript"><!--
function initInteractions(){}
//--></script><script language="javascript">
var intDelay=50; //设置菜单显示速度,越大越慢
var intInterval=5; //每次更改的透明度
function MenuClick()
{
if (LayerMenu.style.display=="")
{
GradientClose();
}
else{
LayerMenu.filters.alpha.opacity=0;
LayerMenu.style.display="";
GradientShow();
}
} function GradientShow() //实现淡入的函数
{
LayerMenu.filters.alpha.opacity+=intInterval;
if (LayerMenu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay);
}
function GradientClose() //实现淡出的函数
{
LayerMenu.filters.alpha.opacity-=intInterval;
if (LayerMenu.filters.alpha.opacity>0) {
setTimeout("GradientClose()",intDelay);
}
else {
LayerMenu.style.display="none";
}
}
function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的
{
oEl=event.srcElement;
if (oEl.style.background!="navy") {
oEl.style.background="navy";
}
else {
oEl.style.background="#cccccc";
}
}
function ItemClick() //在菜单项上单击后打开相应链接
{
oEl=event.srcElement;
oLink=oEl.all.tags( "A" );
if( oLink.length )
{
oLink[0].click();
GradientClose();
}
}</script>
<style>
.up{BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #666666 1px solid;font-size:9pt;cursor=default}
.down{BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #666666 1px solid;
BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #ffffff 1px solid;font-size:9pt;cursor=default}
.c { font-size: 9pt; cursor: default}.h { font-size: 9pt; color: #FFFFFF;
cursor: default}
</style>
<!--//以上定义CSS-->
</head>
<body><div style="Position:Absolute;Left:200px;Top:256px;width:334px; height:21px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000">
<table border=0 cellpadding=0 cellspacing=0 width=516 height="21">
<tr><script language="JavaScript">
function A()
{
if (LayerMenu.style.display=="")
{
event.srcElement.className='up';
}
else{
event.srcElement.className='down';
}
}</script>
<td width="56"><img id=b class=up onmousedown="A()" onselectstart="return false;" onclick="MenuClick()" src="http://www.1000script.com/pic/win.gif" width="56" height="21" align="absmiddle"></td>
<td class=up onclick="GradientClose();">
<div align="center">人大附中选修课管理系统</div>
</td></tr></table></div> <!--//以上为按钮层-->
<div class=up id=LayerMenu style="Position:Absolute;Left:200px;Top:155px;Display:none;filter:alpha(opacity=0);width: 169px; height: 83px" oncontextmenu="return false" onMouseover="window.event.cancelBubble = true;">
<table border=0 cellpadding=0 cellspacing=0 bgcolor=#CCCCCC width="100%">
<tr><td width=20 valign=bottom bgcolor=navy></td><td>
<table border=0 width=100% cellpadding=0 cellspacing=0 onselectstart="return false;" onClick="ItemClick();" onMouseOver="ChangeBG();" onMouseOut="ChangeBG();">
<tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>教师入口(T)</td></tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>学生入口(D)</td></tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>管理员入口(G)</td>
</tr><tr>
<td class=c onMouseOver="this.className='h'" onMouseOut="this.className='c'" height=25><a href=#></a>浏览检索(S)</td></tr></table></td></tr>
</table></div> <!--//菜单层-->
<div id="body" style="position:absolute; width:938px; height:903px; top: 77px; left: 25px" onmousedown="b.className='up'" onclick="GradientClose();"></div> <!--目的是鼠标单击外面时菜单淡入--></body>
</html>
Thank you!!!
这个可能有帮助:http://www.codeproject.com/cs/menu/vsnetmenu.asp
免费注册后,才能宰
以前在VB里写过,用小窗体代替菜单,在窗体上用MSFlexGrid连着数据库(同时用了各种图标)