Beispiel #1
0
        public void AddRibbonBar(string tabName, RibbonBar ribbonBar)
        {
            RibbonControl ribbonCtrl = this.MainForm.Controls["ribbonControl1"] as RibbonControl;

            if (ribbonCtrl == null)
            {
                throw new Exception("无法找到RibbonContainer。");
            }

            RibbonPanel   ribbonPanel = null;
            RibbonTabItem tabItem;

            foreach (BaseItem item in ribbonCtrl.Items)
            {
                if ((tabItem = item as RibbonTabItem) != null &&
                    string.Equals(Convert.ToString(tabItem.Tag), tabName, StringComparison.OrdinalIgnoreCase))
                {
                    ribbonPanel = tabItem.Panel;
                    break;
                }
            }

            if (ribbonPanel == null)
            {
                throw new Exception("无法找到RibbonPanel。");
            }

            Control lastBar = ribbonPanel.Controls[0];

            ribbonBar.Location = new System.Drawing.Point(lastBar.Location.X + lastBar.Width, lastBar.Location.Y);
            ribbonBar.Size     = new System.Drawing.Size(Math.Max(1, ribbonBar.Width), lastBar.Height);
            ribbonPanel.SuspendLayout();
            ribbonPanel.Controls.Add(ribbonBar);
            ribbonPanel.Controls.SetChildIndex(ribbonBar, 0);
            ribbonPanel.ResumeLayout(false);
        }
Beispiel #2
0
        public void showSysMenu()
        {
            int ritemCount = ribbonControl1.Items.Count - 1;

            for (int i = 0; i < ritemCount; i++)
            {
                ribbonControl1.Items.Remove(0);
            }

            for (int i = 0; i < modules.Count; i++)
            {
                #region 循环插入模块
                DevComponents.DotNetBar.RibbonTabItem ribbonTabItemModule = new RibbonTabItem();
                DevComponents.DotNetBar.RibbonPanel   rPanel = new RibbonPanel();
                ribbonTabItemModule.Panel = rPanel;
                //this.ribbonControl1.SuspendLayout();
                rPanel.SuspendLayout();
                rPanel.Dock                      = DockStyle.Fill;
                rPanel.Name                      = "panel" + modules[i].ModuleId.ToString();
                rPanel.Style.CornerType          = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.Location                  = new Point(0, 0x3a);
                rPanel.Margin                    = new System.Windows.Forms.Padding(3, 4, 3, 4);
                rPanel.Padding                   = new System.Windows.Forms.Padding(3, 0, 3, 4);
                rPanel.Size                      = new Size(0x47a, 0x73);

                //ribbonTabItemModule.Checked = true;
                //ribbonTabItemModule.ItemAlignment = eItemAlignment.Near;
                ribbonTabItemModule.Name        = "module" + modules[i].ModuleId.ToString();
                ribbonTabItemModule.Text        = modules[i].Name;
                ribbonTabItemModule.Tag         = modules[i];
                ribbonTabItemModule.HotFontBold = true;

                DevComponents.DotNetBar.RibbonBar rMenuClass = null;

                #region 增加子菜单
                List <BaseMenu> _menus = menus.FindAll(x => (x.ModuleId == modules[i].ModuleId && x.PMenuId == -1)).OrderByDescending(x => x.SortId).ToList();
                if (_menus.Count > 0)
                {
                    //List<RibbonBar> listbar = new List<RibbonBar>();
                    for (int j = 0; j < _menus.Count; j++)
                    {
                        if (string.IsNullOrEmpty(_menus[j].DllName) && string.IsNullOrEmpty(_menus[j].UrlId))
                        {
                            //为二级分类菜单
                            DevComponents.DotNetBar.RibbonBar menuClass = new RibbonBar();
                            menuClass.AutoOverflowEnabled = true;
                            menuClass.Dock = System.Windows.Forms.DockStyle.Left;
                            menuClass.ContainerControlProcessDialogKey = true;
                            menuClass.Text         = _menus[j].Name;
                            menuClass.TitleVisible = false;
                            //三级菜单
                            List <BaseMenu> mainMenu = menus.FindAll(x => x.PMenuId == _menus[j].MenuId).OrderByDescending(x => x.SortId).ToList();
                            foreach (BaseMenu menu in mainMenu)
                            {
                                DevComponents.DotNetBar.ButtonItem btnmenu = new ButtonItem(menu.MenuId.ToString(), menu.Name);
                                // btnmenu.Image = global::EFWBaseLib.Properties.Resources.defaulttool;
                                if (!string.IsNullOrEmpty(menu.Image) && System.IO.File.Exists(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + menu.Image))
                                {
                                    btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + menu.Image), 24, 24);
                                }
                                else
                                {
                                    btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"images\defaultmenu.ico"), 24, 24);
                                }
                                // btnmenu.ImageListSizeSelection = DevComponents.DotNetBar.eButtonImageListSelection.Large;
                                btnmenu.ImagePosition          = DevComponents.DotNetBar.eImagePosition.Top;
                                btnmenu.Text                   = menu.Name;
                                btnmenu.Tag                    = menu;
                                btnmenu.ImageListSizeSelection = eButtonImageListSelection.Default;
                                //btnmenu.ImagePosition = eImagePosition.Left;
                                btnmenu.Click += new EventHandler(btnmenu_Click);
                                menuClass.Items.Add(btnmenu);
                            }

                            //listbar.Add(menuClass);
                            rPanel.Controls.Add(menuClass);

                            //rPanel.Refresh();
                        }
                        else
                        {
                            //菜单没有二级分类菜单则创建默认二级分类菜单
                            if (rMenuClass == null)
                            {
                                rMenuClass = new RibbonBar();
                                rMenuClass.AutoOverflowEnabled = true;
                                rMenuClass.Dock         = System.Windows.Forms.DockStyle.Left;
                                rMenuClass.Text         = "操作功能";
                                rMenuClass.TitleVisible = false;
                                rPanel.Controls.Add(rMenuClass);
                            }

                            DevComponents.DotNetBar.ButtonItem btnmenu = new ButtonItem(_menus[j].MenuId.ToString(), _menus[j].Name);
                            //btnmenu.Image = global::EFWBaseLib.Properties.Resources.defaulttool;
                            //btnmenu.ImageListSizeSelection = DevComponents.DotNetBar.eButtonImageListSelection.Large;
                            if (!string.IsNullOrEmpty(_menus[j].Image))
                            {
                                btnmenu.Image = Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + _menus[j].Image);
                                btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + _menus[j].Image), 32, 32);
                            }
                            else
                            {
                                btnmenu.Image = Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"images\defaultmenu.ico");
                            }
                            btnmenu.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top;
                            btnmenu.Text          = _menus[j].Name;
                            btnmenu.Tag           = _menus[j];
                            btnmenu.Click        += new EventHandler(btnmenu_Click);
                            rMenuClass.Items.Add(btnmenu);
                        }
                    }
                }
                #endregion

                ribbonControl1.Items.Insert(ribbonControl1.Items.Count - 1, ribbonTabItemModule);
                ribbonControl1.Controls.Add(rPanel);

                rPanel.ResumeLayout(false);
                ribbonTabItemModule.Refresh();

                #endregion
            }

            ribbonControl1.Show();
            //ribbonTabItem1.Visible = false;
            //ribbonTabItem2.Visible = false;
            ribbonControl1.Refresh();
            this.Refresh();
            ribbonControl1.SelectFirstVisibleRibbonTab();
        }
        public void showSysMenu()
        {

            int ritemCount = ribbonControl1.Items.Count - 1;
            for (int i = 0; i < ritemCount; i++)
            {
                ribbonControl1.Items.Remove(0);
            }

            for (int i = 0; i < modules.Count; i++)
            {
                #region 循环插入模块
                DevComponents.DotNetBar.RibbonTabItem ribbonTabItemModule = new RibbonTabItem();
                DevComponents.DotNetBar.RibbonPanel rPanel = new RibbonPanel();
                ribbonTabItemModule.Panel = rPanel;
                //this.ribbonControl1.SuspendLayout();
                rPanel.SuspendLayout();
                rPanel.Dock = DockStyle.Fill;
                rPanel.Name = "panel" + modules[i].ModuleId.ToString();
                rPanel.Style.CornerType = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square;
                rPanel.Location = new Point(0, 0x3a);
                rPanel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
                rPanel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 4);
                rPanel.Size = new Size(0x47a, 0x73);

                //ribbonTabItemModule.Checked = true;
                //ribbonTabItemModule.ItemAlignment = eItemAlignment.Near;
                ribbonTabItemModule.Name = "module" + modules[i].ModuleId.ToString();
                ribbonTabItemModule.Text = modules[i].Name;
                ribbonTabItemModule.Tag = modules[i];

                DevComponents.DotNetBar.RibbonBar rMenuClass = null;

                #region 增加子菜单
                List<BaseMenu> _menus = menus.FindAll(x => (x.ModuleId == modules[i].ModuleId && x.PMenuId == -1)).OrderByDescending(x => x.SortId).ToList();
                if (_menus.Count > 0)
                {
                    //List<RibbonBar> listbar = new List<RibbonBar>();
                    for (int j = 0; j < _menus.Count; j++)
                    {
                        if (string.IsNullOrEmpty(_menus[j].DllName) && string.IsNullOrEmpty(_menus[j].UrlId))
                        {
                            //为二级分类菜单
                            DevComponents.DotNetBar.RibbonBar menuClass = new RibbonBar();
                            menuClass.AutoOverflowEnabled = true;
                            menuClass.Dock = System.Windows.Forms.DockStyle.Left;
                            menuClass.ContainerControlProcessDialogKey = true;
                            menuClass.Text = _menus[j].Name;

                            //三级菜单
                            List<BaseMenu> mainMenu = menus.FindAll(x => x.PMenuId == _menus[j].MenuId).OrderByDescending(x => x.SortId).ToList();
                            foreach (BaseMenu menu in mainMenu)
                            {
                                DevComponents.DotNetBar.ButtonItem btnmenu = new ButtonItem(menu.MenuId.ToString(), menu.Name);
                                // btnmenu.Image = global::EFWBaseLib.Properties.Resources.defaulttool;
                                if (!string.IsNullOrEmpty(menu.Image))
                                {
                                    btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + menu.Image), 32, 32);
                                }
                                else
                                {
                                    btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"images\defaultmenu.ico"), 32, 32);
                                }
                                // btnmenu.ImageListSizeSelection = DevComponents.DotNetBar.eButtonImageListSelection.Large;
                                btnmenu.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top;
                                btnmenu.Text = menu.Name;
                                btnmenu.Tag = menu;
                                btnmenu.Click += new EventHandler(btnmenu_Click);
                                menuClass.Items.Add(btnmenu);
                            }

                            //listbar.Add(menuClass);
                            rPanel.Controls.Add(menuClass);

                            //rPanel.Refresh();
                        }
                        else
                        {
                            //菜单没有二级分类菜单则创建默认二级分类菜单
                            if (rMenuClass == null)
                            {
                                rMenuClass = new RibbonBar();
                                rMenuClass.AutoOverflowEnabled = true;
                                rMenuClass.Dock = System.Windows.Forms.DockStyle.Left;
                                rMenuClass.Text = "操作功能";
                                rPanel.Controls.Add(rMenuClass);
                            }

                            DevComponents.DotNetBar.ButtonItem btnmenu = new ButtonItem(_menus[j].MenuId.ToString(), _menus[j].Name);
                            //btnmenu.Image = global::EFWBaseLib.Properties.Resources.defaulttool;
                            //btnmenu.ImageListSizeSelection = DevComponents.DotNetBar.eButtonImageListSelection.Large;
                            if (!string.IsNullOrEmpty(_menus[j].Image))
                            {
                                btnmenu.Image = Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + _menus[j].Image);
                                btnmenu.Image = new Bitmap(Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + _menus[j].Image), 32, 32);
                            }
                            else
                            {
                                btnmenu.Image = Image.FromFile(EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"images\defaultmenu.ico");
                            }
                            btnmenu.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top;
                            btnmenu.Text = _menus[j].Name;
                            btnmenu.Tag = _menus[j];
                            btnmenu.Click += new EventHandler(btnmenu_Click);
                            rMenuClass.Items.Add(btnmenu);
                        }
                    }
                }
                #endregion

                ribbonControl1.Items.Insert(ribbonControl1.Items.Count - 1, ribbonTabItemModule);
                ribbonControl1.Controls.Add(rPanel);

                rPanel.ResumeLayout(false);
                ribbonTabItemModule.Refresh();

                #endregion
            }

            ribbonControl1.Show();
            //ribbonTabItem1.Visible = false;
            //ribbonTabItem2.Visible = false;
            ribbonControl1.Refresh();
            this.Refresh();
            ribbonControl1.SelectFirstVisibleRibbonTab();

        }
Beispiel #4
0
        private void InitMenu()
        {
            var menuList = GlobalVar.PowerMenuList.Where(p => p.IsVisible).ToList();

            RibbonMain.Items.Clear();
            RibbonMain.Items.Add(t1);

            foreach (var menuTab in menuList.Where(p => p.ControlType == "Tab"))
            {
                string menuName = menuTab.ControlType + menuTab.MenuCode;
                var    tab      = new RibbonTabItem
                {
                    Text = menuTab.MenuText,
                    Name = menuName,
                };
                var panel = new RibbonPanel();
                panel.Dock    = DockStyle.Fill;
                panel.Name    = panel + menuName;
                panel.Visible = false;

                foreach (var menuGrp in menuList.Where(p => p.ParentCode == menuTab.MenuCode))
                {
                    var grp = new RibbonBar
                    {
                        Text = menuGrp.MenuText,
                        Name = menuGrp.ControlType + menuGrp.MenuCode,
                    };
                    foreach (var menuItm in menuList.Where(p => p.ParentCode == menuGrp.MenuCode))
                    {
                        var itm = new ButtonItem()
                        {
                            Text = menuItm.MenuText,
                            Name = menuItm.ControlType + menuItm.MenuCode,
                        };
                        itm.Image =
                            (Image)Common.Properties.Resources.ResourceManager.GetObject(menuItm.ImageName ?? "") ??
                            (Image)Common.Properties.Resources.ResourceManager.GetObject("DefaultButton");
                        itm.ImageFixedSize = new Size(50, 50);
                        itm.ButtonStyle    = eButtonStyle.ImageAndText;
                        itm.ImagePosition  = eImagePosition.Top;
                        if (string.IsNullOrEmpty(menuItm.Params))
                        {
                            itm.Click +=
                                delegate
                            {
                                SetMdiForm(menuItm.MenuText,
                                           Type.GetType(menuItm.NameSpace + "." + menuItm.ClassName));
                            };
                        }
                        else
                        {
                            itm.Click +=
                                delegate
                            {
                                object[] strParams = menuItm.Params.Split(',');
                                SetMdiForm(menuItm.MenuText, Type.GetType(menuItm.NameSpace + "." + menuItm.ClassName), strParams);
                            };
                        }
                        grp.Items.Add(itm);
                    }
                    panel.Controls.Add(grp);
                }
                panel.LayoutRibbons();
                tab.Panel = panel;
                RibbonMain.Controls.Add(panel);
                panel.ResumeLayout(false);
                RibbonMain.Items.Add(tab);
            }
        }