Example #1
0
 protected override void OnClosing(CancelEventArgs e)
 {
     base.OnClosing(e);
     if (DialogResult == DialogResult.OK)
     {
         if (role == DialogRole.New)
         {
             navBar.BeginUpdate();
             NavBarGroup    group = NavBarHelper.GetGroupByName(cbeGroup.Text, navBar);
             NavBarItem     item  = new NavBarItem(teCaption.Text);
             NavBarItemLink link  = group.ItemLinks.Add(item);
             group.Expanded      = true;
             item.Tag            = ObjectHelper.GetCorrectUrl(heLink.Text);
             navBar.SelectedLink = link;
             navBar.EndUpdate();
         }
         else
         {
             CurrentItem.Caption = teCaption.Text;
             CurrentItem.Tag     = ObjectHelper.GetCorrectUrl(heLink.Text);
             if (CurrentGroup.Caption != cbeGroup.Text)
             {
                 navBar.BeginUpdate();
                 NavBarGroup group = NavBarHelper.GetGroupByName(cbeGroup.Text, navBar);
                 group.Expanded = true;
                 NavBarItemLink link = group.ItemLinks.Add(CurrentItem);
                 CurrentGroup.ItemLinks.Remove(navBar.SelectedLink);
                 navBar.SelectedLink = link;
                 NavBarHelper.DeleteEmptyGroup(navBar);
                 navBar.EndUpdate();
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// 实现接口, 创建NavBarControl组件
        /// </summary>
        /// <param name="mainMenu">系统主菜单</param>
        /// <param name="navBar">NavBarControl组件</param>
        public virtual void CreateNavigator(MenuStrip mainMenu, NavBarControl navBar)
        {
            try
            {
                navBar.BeginUpdate();
                navBar.Groups.Clear();
                navBar.Items.Clear();

                //枚举系统主菜单的模块菜单
                foreach (ToolStripMenuItem moduleMenu in mainMenu.Items)
                {
                    //取到菜单,然后递归所有子菜单项创建NavBarControl
                    if (moduleMenu != null && moduleMenu.Enabled)//创建该模块的NavBarButton.
                    {
                        this.CreateNavBarButton(navBar, moduleMenu, moduleMenu.Text);
                    }
                }

                //没有任何模块(Groups数目为0)则创建一个空的Group, 注:每个Group对应一个模块.
                if (navBar.Groups.Count == 0)
                {
                    navBar.Groups.Add(new NavBarGroup(""));
                }

                navBar.EndUpdate();
            }
            catch (Exception ex) { Msg.ShowException(ex); }
        }
Example #3
0
        static void textEdit_EditValueChanged(object sender, EventArgs e)
        {
            navBarControl.BeginUpdate();
            foreach (NavBarGroup group in navBarControl.Groups)
            {
                foreach (NavBarItemLink link in group.ItemLinks)
                {
                    switch (criteria)
                    {
                    case SearchCriteria.Contains:
                        link.Visible = link.Caption.Contains(textEdit.Text);
                        break;

                    case SearchCriteria.StartsWith:
                        link.Visible = link.Caption.StartsWith(textEdit.Text);
                        break;

                    case SearchCriteria.Equals:
                        link.Visible = link.Caption.Equals(textEdit.Text);
                        break;
                    }
                    if (group.VisibleItemLinks.Count == 0)
                    {
                        group.Visible = false;
                    }
                    else
                    {
                        group.Visible = true;
                    }
                }
            }
            navBarControl.EndUpdate();
        }
Example #4
0
        public static void CreateNavBarItem(this NavBarControl bar, DataTable dt, ImageCollection images)
        {
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                {
                    return;
                }
                NavBarItem  navItem   = null;
                NavBarGroup navGroup  = null;
                var         groupName = String.Empty;

                bar.BeginUpdate();

                bar.Items.Clear();
                bar.Groups.Clear();

                foreach (DataRow dr in dt.Rows)
                {
                    if (Convert.ToInt32(dr["CHILD_COUNT"]) > 0)
                    {
                        groupName = string.Format("navGroup_{0}", dr["MNU_ID"]);
                        navGroup  = bar.GetNavBarGroup(groupName, dr["MNU_NM"].ToString());
                        if (images != null)
                        {
                            navGroup.SmallImage = images.Images[0];
                        }
                        navGroup.Visible = true;
                    }
                    else
                    {
                        groupName    = string.Format("navGroup_{0}", dr["PARENT_MNU_ID"]);
                        navGroup     = bar.GetNavBarGroup(groupName, dr["PARENT_MNU_NM"].ToString());
                        navItem      = new NavBarItem(dr["MNU_NM"].ToString());
                        navItem.Name = string.Format("navItem_{0}", dr["MNU_ID"]);
                        if (images != null)
                        {
                            navItem.SmallImage = images.Images[2];
                        }
                        navItem.Visible = true;
                        navItem.Enabled = true;
                        navItem.Tag     = dr["MNU_ID"];
                        navGroup.ItemLinks.Add(navItem);
                        bar.Items.Add(navItem);
                    }
                }
                bar.EndUpdate();
            }
            catch
            {
                throw;
            }
        }
Example #5
0
        /// <summary>
        /// 跟据菜单创建导航组件
        /// </summary>
        /// <param name="navBarControl">导航控件</param>
        /// <param name="mainMenu">主菜单</param>
        /// <param name="style">导航控件的自定义显示类型</param>
        public void CreateNavBarButtons(NavBarControl navBarControl, MenuStrip mainMenu, NavigatorStyle style)
        {
            //跟据用户选择样式创建不同类型的Navigator
            NavigatorBase creator;

            //支持两种策略
            if (NavigatorStyle.BarItem == style)
            {
                creator = new NavigatorBarList(this);
            }
            else
            {
                creator = new NavigatorTreeView(this);
            }

            navBarControl.BeginUpdate();
            creator.CreateNavigator(mainMenu, navBarControl);
            navBarControl.EndUpdate();
        }
Example #6
0
 public static void FillNavBar(NavBarControl navBar, NavBarGroupStyle groupStyle, NavBarImage groupCaptionImage)
 {
     if (navBar == null)
     {
         return;
     }
     navBar.BeginUpdate();
     for (int i = 0; i < Count; i++)
     {
         if (GetItem(i).Group == ConstStrings.Get("AboutGroup"))
         {
             continue;
         }
         NavBarItem item = new NavBarItem();
         navBar.Items.Add(item);
         item.Caption = GetItem(i).Name;
         item.Tag     = GetItem(i);
         GetNavBarGroup(navBar, GetItem(i).Group, groupStyle, groupCaptionImage).ItemLinks.Add(new NavBarItemLink(item));
     }
     navBar.EndUpdate();
 }
Example #7
0
        /// <summary>
        /// 跟据菜单创建导航组件
        /// </summary>
        /// <param name="navBarControl">导航控件</param>
        /// <param name="mainMenu">主菜单</param>
        /// <param name="style">导航控件的自定义显示类型</param>
        public void CreateNavBarButtons(NavBarControl navBarControl, MenuStrip mainMenu, NavigatorStyle style)
        {
            //跟据用户选择样式创建不同类型的Navigator
            NavigatorBase creator;

            //支持两种策略
            if (NavigatorStyle.BarItem == style)
                creator = new NavigatorBarList(this);
            else
                creator = new NavigatorTreeView(this);

            navBarControl.BeginUpdate();
            creator.CreateNavigator(mainMenu, navBarControl);
            navBarControl.EndUpdate();
        }
Example #8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a NavBarControl.
            NavBarControl navBar = new NavBarControl();

            this.Controls.Add(navBar);
            navBar.Width = 150;
            navBar.Dock  = DockStyle.Left;
            // Apply the "NavigationPaneView" style.
            navBar.PaintStyleKind = NavBarViewKind.NavigationPane;

            // Create the 'Charts' navbar group.
            NavBarGroup groupChart = new NavBarGroup("Charts");

            // Display a large image in the group caption.
            groupChart.LargeImage = global::AptechSchool.Properties.Resources.chart_32x32;
            // Create an 'Area' item and assign an image to it from the project resources.
            NavBarItem itemChartArea = new NavBarItem("Area");

            itemChartArea.LargeImage = global::AptechSchool.Properties.Resources.area_32x32;
            // Create a 'Bar' item.
            NavBarItem itemChartBar = new NavBarItem("Bar");

            itemChartBar.LargeImage = global::AptechSchool.Properties.Resources.bar_32x32;
            // Create a disabled 'Refresh' item.
            NavBarItem itemChartRefresh = new NavBarItem("Refresh");

            itemChartRefresh.LargeImage = global::AptechSchool.Properties.Resources.refresh_32x32;
            itemChartRefresh.Enabled    = false;

            //Assign an image collection to the NavBarControl.
            //Images from this collection are used in the 'Settings' navbar group
            navBar.LargeImages = imageCollection1;

            // Create the 'Settings' navbar group.
            NavBarGroup groupSettings = new NavBarGroup("Settings");

            // Display a large image in the group caption.
            groupSettings.LargeImage = global::AptechSchool.Properties.Resources.customize_32x32;
            // Create an 'Edit Settings' item and assign a large image to it by its index in the navBar.LargeImages collection.
            NavBarItem itemEditSettings = new NavBarItem("Edit Settings");

            itemEditSettings.LargeImageIndex = 0;
            // Create an Export item and assign a large image to it by its index in the navBar.LargeImages collection.
            NavBarItem itemExport = new NavBarItem("Export");

            itemExport.LargeImageIndex = 1;

            // Add the created items to the groups and the groups to the NavBarControl.
            // Prevent excessive updates using the BeginUpdate and EndUpdate methods.
            navBar.BeginUpdate();

            navBar.Groups.Add(groupChart);
            groupChart.ItemLinks.Add(itemChartArea);
            groupChart.ItemLinks.Add(itemChartBar);
            // Add a separator.
            groupChart.ItemLinks.Add(new NavBarSeparatorItem());
            groupChart.ItemLinks.Add(itemChartRefresh);
            //Enable the display of large images in the group.
            groupChart.GroupStyle = NavBarGroupStyle.LargeIconsText;

            navBar.Groups.Add(groupSettings);
            groupSettings.ItemLinks.Add(itemEditSettings);
            groupSettings.ItemLinks.Add(itemExport);
            //Enable the display of large images in the group.
            groupSettings.GroupStyle = NavBarGroupStyle.LargeIconsText;

            // Activate the 'Charts' group.
            navBar.ActiveGroup = groupChart;

            // Specify the event handler to process item clicks.
            //  navBar.LinkClicked += new NavBarLinkEventHandler(navBar_LinkClicked);
            // Specify the event handler to process item selection.
            //navBar.SelectedLinkChanged += navBar_SelectedLinkChanged;

            // Enable link selection.
            // Each group can have a single selected link independent of other groups.
            // When a group is activated and it has no selected link, the first link is auto-selected.
            // At runtime, you will see that the SelectedLinkChanged event fires on group activation,
            // while the LinkClicked event does not.
            navBar.LinkSelectionMode = LinkSelectionModeType.OneInGroupAndAllowAutoSelect;
            navBar.EndUpdate();

            // Manually select the second link:
            //groupChart.SelectedLinkIndex = 1;
        }