Details for a context button action event.
Наследование: KryptonContextMenuEventArgs
Пример #1
0
        private void OnOpeningContextMenu(object sender, CancelEventArgs e)
        {
            // Ignore call as view builder is already destructed
            if (!IsDisposed && (_viewBuilder != null))
            {
                if (DesignMode)
                {
                    // Never show the context menu at design time
                    e.Cancel = true;
                }
                else
                {
                    // Get access to the menu items for selecting a page
                    KryptonContextMenu contextMenu = (KryptonContextMenu)sender;

                    // Kill any existing contents and add a items collection for the page entries
                    contextMenu.Items.Clear();
                    KryptonContextMenuItems contextMenuItems = new KryptonContextMenuItems();
                    contextMenu.Items.Add(contextMenuItems);

                    // Process each page for those that need adding to context strip
                    int menuItems = 0;
                    foreach (KryptonPage page in Pages)
                    {
                        // We always add the currently selected page and
                        // any other that is both visible and enabled
                        if ((page == SelectedPage) || (page.LastVisibleSet && page.Enabled))
                        {
                            // Add a vertical break after every 20 items
                            if ((menuItems > 0) && (menuItems % 20) == 0)
                            {
                                KryptonContextMenuSeparator vertBreak = new KryptonContextMenuSeparator();
                                vertBreak.Horizontal = false;
                                contextMenuItems.Items.Add(vertBreak);
                            }

                            // Create a menu item for the page
                            KryptonContextMenuItem pageMenuItem = new KryptonContextMenuItem(page.GetTextMapping(Button.ContextMenuMapText),
                                                                                             page.GetImageMapping(Button.ContextMenuMapImage),
                                                                                             new EventHandler(OnContextMenuClick));

                            // Should the item be enabled?
                            pageMenuItem.Enabled = page.Enabled;

                            // The selected page should be checked
                            pageMenuItem.Checked = (page == SelectedPage);

                            // Use tag to store a back reference to the page
                            pageMenuItem.Tag = page;

                            // Add to end of the strip
                            contextMenuItems.Items.Add(pageMenuItem);
                            menuItems++;
                        }
                    }

                    // Create the event arguments
                    ContextActionEventArgs cae = new ContextActionEventArgs(SelectedPage,
                                                                            SelectedIndex,
                                                                            Button.ContextButtonAction,
                                                                            contextMenu);

                    if (ContextAction != null)
                        ContextAction(this, cae);

                    // Process the requested action
                    switch (cae.Action)
                    {
                        case ContextButtonAction.SelectPage:
                            // Do nothing, allow context menu to be shown
                            break;
                        default:
                            // Cancel the showing of the context menu
                            e.Cancel = true;
                            break;
                    }
                }
            }
        }
Пример #2
0
 private void kryptonNavigator1_ContextAction(object sender, ContextActionEventArgs e)
 {
     // Because the 'new page' item does not have any text we need to manually set the
     // displayed text for 'new page' in the context menu strip, otherwise it will be blank
     KryptonContextMenuItems items = (KryptonContextMenuItems)e.KryptonContextMenu.Items[0];
     KryptonContextMenuItem item = (KryptonContextMenuItem)items.Items[items.Items.Count - 1];
     item.Text = "New Page";
 }
Пример #3
0
 private void kryptonNavigator1_ContextAction(object sender, ContextActionEventArgs e)
 {
     AddOutput("ContextAction");
 }