Ejemplo n.º 1
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);
            }
        }