问题描述
不能上傳,我就把源碼貼出來吧,選下載一個DotNetBar.dll,拉一個sidebar控件,主要讀取菜單然後放到sidebar控件,研究了一天-但是現在不能綁定菜單事件,希望高手來改寫一下,使之能綁定菜單的click事件privatevoidInitMenu(){intpicii=10;DevComponents.DotNetBar.BaseItem[]baseitem=newDevComponents.DotNetBar.BaseItem[menuStrip1.Items.Count];System.Windows.Forms.ToolStripMenuItemsubmenuitem=newSystem.Windows.Forms.ToolStripMenuItem();for(intii=0;ii<menuStrip1.Items.Count;ii++){try{baseitem[ii]=newDevComponents.DotNetBar.SideBarPanelItem();baseitem[ii].Name=menuStrip1.Items[ii].Name.ToString();baseitem[ii].Text=menuStrip1.Items[ii].Text.ToString();submenuitem=(ToolStripMenuItem)menuStrip1.Items[ii];DevComponents.DotNetBar.ButtonItem[]buttonitem=newDevComponents.DotNetBar.ButtonItem[submenuitem.DropDownItems.Count];for(inti=0;i<submenuitem.DropDownItems.Count;i++){if(submenuitem.DropDownItems[i].Text==""){continue;}DevComponents.DotNetBar.ButtonItemblnitem=newDevComponents.DotNetBar.ButtonItem(submenuitem.DropDownItems[i].Name,submenuitem.DropDownItems[i].Text);blnitem.ButtonStyle=DevComponents.DotNetBar.eButtonStyle.TextOnlyAlways;blnitem.ImagePaddingHorizontal=8;blnitem.ImagePosition=DevComponents.DotNetBar.eImagePosition.Top;baseitem[ii].SubItems.Add(blnitem);}sideBar1.Panels.Add(baseitem[ii]);sideBar1.Refresh();}catch(System.Exceptionex){MessageBox.Show(ex.ToString());}}}
解决方案
解决方案二:
up
解决方案三:
希望大家都來頂一下
解决方案四:
up
解决方案五:
用的是组件
解决方案六:
我一兆多不好上传,首先下载DevComponents.DotNetBar.dll然后拉入一个sidebar控件,下面InitMenu()方法初始化sidebar控件使之与菜单一致,最下面的就是绑定其对应菜单事件publicFormMain(){InitializeComponent();InitMenu();toolStripStatusLabel3.Text="操作员:"+Conn.loginname;}privatevoidInitMenu(){DevComponents.DotNetBar.BaseItem[]baseitem=newDevComponents.DotNetBar.BaseItem[menuStrip1.Items.Count];System.Windows.Forms.ToolStripMenuItemsubmenuitem=newSystem.Windows.Forms.ToolStripMenuItem();for(intii=0;ii<menuStrip1.Items.Count;ii++){try{baseitem[ii]=newDevComponents.DotNetBar.SideBarPanelItem(menuStrip1.Items[ii].Name.ToString(),menuStrip1.Items[ii].Text.ToString());submenuitem=(ToolStripMenuItem)menuStrip1.Items[ii];submenuitem.Image=menuStrip1.Items[ii].Image;DevComponents.DotNetBar.ButtonItem[]buttonitem=newDevComponents.DotNetBar.ButtonItem[submenuitem.DropDownItems.Count];for(inti=0;i<submenuitem.DropDownItems.Count;i++){if(submenuitem.DropDownItems[i].Text==""||submenuitem.DropDownItems[i].Text.Trim()=="-"){continue;}DevComponents.DotNetBar.ButtonItemblnitem=newDevComponents.DotNetBar.ButtonItem(submenuitem.DropDownItems[i].Name,submenuitem.DropDownItems[i].Text);blnitem.ButtonStyle=DevComponents.DotNetBar.eButtonStyle.ImageAndText;blnitem.Image=submenuitem.DropDownItems[i].Image;blnitem.ImagePaddingHorizontal=8;blnitem.ImagePosition=DevComponents.DotNetBar.eImagePosition.Top;baseitem[ii].SubItems.Add(blnitem);}sideBar1.Panels.Add(baseitem[ii]);sideBar1.Refresh();}catch(System.Exceptionex){MessageBox.Show(ex.ToString());}}}privatevoidsideBar1_ItemClick(objectsender,EventArgse){System.Windows.Forms.ToolStripMenuItemsubmenuitem=newSystem.Windows.Forms.ToolStripMenuItem();if(senderisDevComponents.DotNetBar.ButtonItem){DevComponents.DotNetBar.ButtonItemitem=senderasDevComponents.DotNetBar.ButtonItem;for(intii=0;ii<menuStrip1.Items.Count;ii++){submenuitem=(ToolStripMenuItem)menuStrip1.Items[ii];for(intiii=0;iii<submenuitem.DropDownItems.Count;iii++){if(item.Name.Trim()==submenuitem.DropDownItems[iii].Name.Trim()){submenuitem.DropDownItems[iii].PerformClick();}}}}}