当前位置:编程学习 > C#/ASP.NET >>

c#outlook樣式源易做图,希望對對來的有所幫助

不能上傳,我就把源易做图貼出來吧,選下載一個DotNetBar.dll,拉一個sidebar控件,主要讀取菜單然後放到sidebar 控件,研究了一天-但是現在不能綁定菜單事件,希望高手來改寫一下,使之能綁定菜單的click事件
   private void InitMenu()
        {
            int picii = 10;
            DevComponents.DotNetBar.BaseItem[] baseitem = new DevComponents.DotNetBar.BaseItem[menuStrip1.Items.Count];            
            System.Windows.Forms.ToolStripMenuItem submenuitem = new System.Windows.Forms.ToolStripMenuItem();
            for (int ii = 0; ii < menuStrip1.Items.Count; ii++)
            {
                try
                {
                    baseitem[ii] =  new DevComponents.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 = new DevComponents.DotNetBar.ButtonItem[submenuitem.DropDownItems.Count];
                     for (int i = 0; i < submenuitem.DropDownItems.Count; i++)
                     {
                         if (submenuitem.DropDownItems[i].Text == "") { continue; }
                         DevComponents.DotNetBar.ButtonItem blnitem = new DevComponents.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.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }
        } --------------------编程问答-------------------- up --------------------编程问答-------------------- 希望大家都來頂一下 --------------------编程问答-------------------- up --------------------编程问答-------------------- 用的是组件 --------------------编程问答-------------------- 我一兆多不好上传,首先下载
DevComponents.DotNetBar.dll
然后拉入一个sidebar控件,下面InitMenu()方法初始化sidebar控件使之与菜单一致,最下面的就是绑定其对应菜单事件

   public FormMain()
        {
            InitializeComponent();
            InitMenu();
            toolStripStatusLabel3.Text ="  操作员:"+Conn.loginname;
   
        }
        private void InitMenu()
        {
            DevComponents.DotNetBar.BaseItem[] baseitem = new DevComponents.DotNetBar.BaseItem[menuStrip1.Items.Count];
            System.Windows.Forms.ToolStripMenuItem submenuitem = new System.Windows.Forms.ToolStripMenuItem();
            for (int ii = 0; ii < menuStrip1.Items.Count; ii++)
            {
                try
                {
                    baseitem[ii] = new DevComponents.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 = new DevComponents.DotNetBar.ButtonItem[submenuitem.DropDownItems.Count];
                    for (int i = 0; i < submenuitem.DropDownItems.Count; i++)
                    {
                        if (submenuitem.DropDownItems[i].Text == "" || submenuitem.DropDownItems[i].Text.Trim() == "-") { continue; }
                        DevComponents.DotNetBar.ButtonItem blnitem = new DevComponents.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.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

        private void sideBar1_ItemClick(object sender, EventArgs e)
        {
               System.Windows.Forms.ToolStripMenuItem submenuitem = new System.Windows.Forms.ToolStripMenuItem();
            if (sender is DevComponents.DotNetBar.ButtonItem)
            {
                DevComponents.DotNetBar.ButtonItem item = sender as DevComponents.DotNetBar.ButtonItem;
                for (int ii = 0; ii < menuStrip1.Items.Count; ii++)
                {
                    submenuitem = (ToolStripMenuItem)menuStrip1.Items[ii];
                    for (int iii = 0; iii < submenuitem.DropDownItems.Count; iii++)
                    {
                        if (item.Name.Trim() == submenuitem.DropDownItems[iii].Name.Trim())
                        {
                            submenuitem.DropDownItems[iii].PerformClick();
                        }
                    }
                }
            } 
        }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,