C# 给Button添加一下拉菜单功能

No4000 2008-05-22 08:56:56
如题
...全文
613 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
qgj1655 2008-08-02
  • 打赏
  • 举报
回复
为什么不用contextMenuStrip控件呢
xiezhiqu 2008-08-01
  • 打赏
  • 举报
回复
回13楼:
[Quote=引用 15 楼 xiezhiqu 的回复:]
用一个名叫dotnetbar的第三方控件,里面的buttonX控件就可以添加下拉的button按纽。
[/Quote]
再把buttonX的AutoExpandOnClick属性设为true就可以了。
xiezhiqu 2008-08-01
  • 打赏
  • 举报
回复
用一个名叫dotnetbar的第三方控件,里面的buttonX控件就可以添加下拉的button按纽。
wuhaiwuya 2008-08-01
  • 打赏
  • 举报
回复
1、 重写button 组件 屏蔽右键功能 overrid wnproc
2、 button ContextMenuStrip 设置控件
3、 button click 添加如下代码
this.btn_name.ContextMenuStrip.show(this.btn_name,new point(0,this.btn_name.height);
这样单机左键时就会再button 下边出现菜单
baggio582 2008-08-01
  • 打赏
  • 举报
回复
我想单击左键实现下拉的效果该怎么做??!
liulcster 2008-05-22
  • 打赏
  • 举报
回复
在画面上追加一个ContextMenuStrip控件,
然后在你的button的ContextMenuStrip属性设置成刚才追加的ContextMenuStrip控件
运行时鼠标右击就可以了
No4000 2008-05-22
  • 打赏
  • 举报
回复
jjjjj102310253 谢谢,我正是做C/S的, 以后用得着吧
andyzhao12 2008-05-22
  • 打赏
  • 举报
回复
学到不少东东呀。
DNN-2017 2008-05-22
  • 打赏
  • 举报
回复
然后botton是用图片对于焦点事件可以有凹凸的视觉感。我们是B/S的如果是C/S应该有其他的做法
DNN-2017 2008-05-22
  • 打赏
  • 举报
回复
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="下拉菜单.aspx.cs" Inherits="System_PriceStantard_下拉菜单" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>打造下拉菜单</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
body,td { font-size:12px; font-family:宋体}
a:link { color: #ffffff; text-decoration: none}
a:visited { color: #ffffff; text-decoration: none}
a:hover { color: #ff9933; text-decoration: none}
table { border: #000000; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</style>
<script language="JavaScript">
<!--
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//鼠标焦点事件的相应
function MM_showHideLayers()
{ //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
{
if ((obj=MM_findObj(args[i]))!=null)
{
v=args[i+2];
if (obj.style)
{
obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;
}
obj.visibility=v;
}
}
}
//-->
</script>
</head>

<body bgcolor="#CCCCCC" text="#000000" leftmargin="0" topmargin="0" scroll=auto>
<div id="title" style="position:absolute; left:8px; top:15px; width:240px; height:15px; z-index:1; background-color: #006699; border: 1px none #000000">
<table width="480" cellspacing="0" cellpadding="2">
<tr>
<td width="120" onMouseOver="MM_showHideLayers('menu1','','show')" onMouseOut="MM_showHideLayers('menu1','','hide')"><b><font color="#FFFFFF"><a href="#">■
经典论坛</a></font></b> </td>
<td width="120" onMouseOver="MM_showHideLayers('menu2','','show')" onMouseOut="MM_showHideLayers('menu2','','hide')"><b><font color="#FFFFFF"><a href="#">■
天极网</a></font></b> </td>
<td width="120" onMouseOver="MM_showHideLayers('menu2','','show')" onMouseOut="MM_showHideLayers('menu2','','hide')"> </td>
<td width="120" onMouseOver="MM_showHideLayers('menu2','','show')" onMouseOut="MM_showHideLayers('menu2','','hide')"> </td>
</tr>
</table>
</div>
<div id="menu1" style="position:absolute; left:8px; top:34px; width:120px; height:80px; z-index:2; background-color: #999966; border: 1px none #000000; visibility: hidden" onMouseOver="MM_showHideLayers('menu1','','show')" onMouseOut="MM_showHideLayers('menu1','','hide')">
<table width="100%" cellspacing="0" cellpadding="2" height="80">
<tr>
<td> <a href="http://www.baidu.com/">Dreamweaver 专栏</a></td>
</tr>
<tr>
<td> <a href="http://www.baidu.com/">Fireworks 专栏</a></td>
</tr>
<tr>
<td> <a href="http://www.baidu.com/">Flash 基本操作</a></td>
</tr>
<tr>
<td> <a href="http://www.baidu.com/">Flash 5 Action</a></td>
</tr>
</table>
</div>
<div id="menu2" style="position:absolute; left:127px; top:34px; width:120px; height:80px; z-index:2; background-color: #999966; border: 1px none #000000; visibility: hidden" onMouseOver="MM_showHideLayers('menu2','','show')" onMouseOut="MM_showHideLayers('menu2','','hide')">
<table width="100%" cellspacing="0" cellpadding="2" height="80">
<tr>
<td> <a href="http://www.baidu.com/">新闻</a> </td>
</tr>
<tr>
<td height="20"> <a href="http://www.baidu.com/">软件</a></td>
</tr>
<tr>
<td> <a href="http://www.baidu.com/">硬件</a> </td>
</tr>
<tr>
<td> <a href="http://www.baidu.com/">商城</a></td>
</tr>
</table>
</div>

<!-- START NNR Site Census V5.1 -->
<!-- COPYRIGHT 2004 Nielsen // Netratings -->
<script language="JavaScript" type="text/javascript">
<!--
var _rsCI="cn-pconline";
var _rsCG="0";
var _rsDT=0;
var _rsDU=0;
var _rsDO=0;
var _rsX6=0;
var _rsSI=escape(window.location);
var _rsLP=location.protocol.indexOf('https')>-1?'https:':'http:';
var _rsRP=escape(document.referrer);
var _rsND=_rsLP+'//secure-cn.imrworldwide.com/';

if (parseInt(navigator.appVersion)>=4)
{
var _rsRD=(new Date()).getTime();
var _rsSE=1;
var _rsSV="";
var _rsSM=0.01;
_rsCL='<scr'+'ipt language="JavaScript" type="text/javascript" src="'+_rsND+'v51.js"><\/scr'+'ipt>';
}
else
{
_rsCL='<img src="'+_rsND+'cgi-bin/m?ci='+_rsCI+'&cg='+_rsCG+'&si='+_rsSI+'&rp='+_rsRP+'">';
}
document.write(_rsCL);
//-->
</script>
<noscript>
<img src="//secure-cn.imrworldwide.com/cgi-bin/m?ci=cn-pconline&cg=0" alt="">
</noscript>
<!-- END NNR Site Census V5.1 -->
</BODY>

</html>
wuhaiwuya 2008-05-22
  • 打赏
  • 举报
回复
自定义控件 button与combox 组合 定义好事件就可以
No4000 2008-05-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 huarui799 的回复:]
用ComBoBox空间 代替 Button 就可以了 功能都一样的 不会影响你的使用
[/Quote]
不符合项目的须要
red_fish 2008-05-22
  • 打赏
  • 举报
回复
同意三楼的。
DNN-2017 2008-05-22
  • 打赏
  • 举报
回复
是用javascript写的我找找具体的代码
huarui799 2008-05-22
  • 打赏
  • 举报
回复
用ComBoBox空间 代替 Button 就可以了 功能都一样的 不会影响你的使用
goldxinx 2008-05-22
  • 打赏
  • 举报
回复
自定义控件
ojekleen 2008-05-22
  • 打赏
  • 举报
回复
重写一个控件,把BUTTON和COMBOBOX放一起,写相应事件就可以了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧