public MenuBoxItemCollection(MenuBox owner)
 {
     this.owner = owner;
 }
示例#2
0
        private void WmReflectNotifyChevronPushed(ref Message m)
        {
            NativeMethods.NMREBARCHEVRON nrch = (NativeMethods.NMREBARCHEVRON)m.GetLParam(typeof(NativeMethods.NMREBARCHEVRON));
            RebarBand   band      = Bands[nrch.wID];
            ContextMenu childMenu = new ContextMenu();

            if (band.Control != null && band.Control is ToolBox)
            {
                ToolBox            toolBar = band.Control as ToolBox;
                NativeMethods.RECT lpRect  = new NativeMethods.RECT();
                UnsafeNativeMethods.GetClientRect(new HandleRef(band.Control, band.Control.Handle), ref lpRect);
                int count = (int)UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                if (count != toolBar.buttonsCount)
                {
                    throw new ArgumentOutOfRangeException("count");
                }
                for (int i = 0; i < count; i++)
                {
                    NativeMethods.RECT brc = new NativeMethods.RECT();
                    UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_GETITEMRECT, i, ref brc);
                    if (brc.right >= (lpRect.right - lpRect.left))
                    {
                        ToolBoxButton btn = toolBar.Buttons[i];
                        if ((btn.Appearance & TBBAppearance.Separator) == 0)
                        {
                            string text = string.Empty;
                            if (!string.IsNullOrEmpty(btn.Text))
                            {
                                text = btn.Text;
                            }
                            else if (!string.IsNullOrEmpty(btn.ToolTipText))
                            {
                                text = btn.ToolTipText;
                            }
                            else
                            {
                                text = btn.MenuText;
                            }
                            MenuItem menuItem = null;
                            if (btn.Enable)
                            {
                                menuItem     = new MenuItem(text, OnMenuItemClick);
                                menuItem.Tag = btn;
                                toolBar.Renderer.SetEnable(menuItem, true);
                            }
                            else
                            {
                                menuItem = new MenuItem(text);
                                toolBar.Renderer.SetEnable(menuItem, false);
                            }
                            toolBar.Renderer.SetImageIndex(menuItem, btn.ImageIndex);
                            childMenu.MenuItems.Add(menuItem);
                            if (btn.DropDownMenu != null)
                            {
                                foreach (MenuItem item in btn.DropDownMenu.MenuItems)
                                {
                                    MenuItem newMenuItem = new MenuItem(item.Text, OnMenuSubItemClick);
                                    newMenuItem.Tag = item;
                                    menuItem.MenuItems.Add(newMenuItem);
                                }
                            }
                        }
                    }
                }
            }
            if (band.Control != null && band.Control is MenuBox)
            {
                MenuBox            menuBar = band.Control as MenuBox;
                NativeMethods.RECT lpRect  = new NativeMethods.RECT();
                UnsafeNativeMethods.GetClientRect(new HandleRef(band.Control, band.Control.Handle), ref lpRect);
                int count = (int)UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                if (count != menuBar.itemsCount)
                {
                    throw new ArgumentOutOfRangeException("count");
                }
                for (int i = 0; i < count; i++)
                {
                    NativeMethods.RECT brc = new NativeMethods.RECT();
                    UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_GETITEMRECT, i, ref brc);
                    if (brc.right >= (lpRect.right - lpRect.left))
                    {
                        MenuBoxItem menuBarItem = menuBar.Items[i];
                        MenuItem    menuItem    = new MenuItem(menuBarItem.Text);
                        childMenu.MenuItems.Add(menuItem);
                        if (menuBarItem.DropDownMenu != null)
                        {
                            foreach (MenuItem item in menuBarItem.DropDownMenu.MenuItems)
                            {
                                MenuItem newMenuItem = new MenuItem(item.Text, OnMenuSubItemClick);
                                newMenuItem.Tag = item;
                                menuItem.MenuItems.Add(newMenuItem);
                            }
                        }
                    }
                }
            }
            childMenu.Show(this, new Point(nrch.rc.left, nrch.rc.bottom));
        }