Exemple #1
0
        private void Sp_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
        {
            SpreadsheetControl control = sender as SpreadsheetControl;

            if (e.MenuType == SpreadsheetMenuType.Cell)
            {
                e.Menu.RemoveMenuItem(SpreadsheetCommandId.InsertHyperlinkContextMenuItem);
                ISpreadsheetCommandFactoryService service = (ISpreadsheetCommandFactoryService)control.GetService(typeof(ISpreadsheetCommandFactoryService));

                //SpreadsheetMenuItemCommandWinAdapter adapter = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.FileNew));
                //SpreadsheetMenuItem item = (SpreadsheetMenuItem)adapter.CreateMenuItem(DXMenuItemPriority.Normal);
                //item.BeginGroup = true;
                //item.Caption = "新建";
                //e.Menu.Items.Add(item);

                //SpreadsheetMenuItemCommandWinAdapter adapter2 = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.FileOpen));
                //var item2 = (SpreadsheetMenuItem)adapter2.CreateMenuItem(DXMenuItemPriority.Normal);
                //item2.Caption = "打开Excel文件";
                //e.Menu.Items.Add(item2);

                SpreadsheetMenuItemCommandWinAdapter adapter3 = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.FileSaveAs));
                var item3 = (SpreadsheetMenuItem)adapter3.CreateMenuItem(DXMenuItemPriority.Normal);
                item3.Caption = "另存为";
                e.Menu.Items.Add(item3);

                SpreadsheetMenuItemCommandWinAdapter adapter4 = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.FilePrintPreview));
                var item4 = (SpreadsheetMenuItem)adapter4.CreateMenuItem(DXMenuItemPriority.Normal);
                item4.Caption = "打印预览";
                e.Menu.Items.Add(item4);

                SpreadsheetMenuItemCommandWinAdapter adapter5 = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.ViewShowGridlines));
                var item5 = (SpreadsheetMenuItem)adapter5.CreateMenuItem(DXMenuItemPriority.Normal);
                item5.Caption = "显示/隐藏网格线";
                e.Menu.Items.Add(item5);

                SpreadsheetMenuItemCommandWinAdapter adapter6 = new SpreadsheetMenuItemCommandWinAdapter(service.CreateCommand(SpreadsheetCommandId.ViewShowHeadings));
                var item6 = (SpreadsheetMenuItem)adapter6.CreateMenuItem(DXMenuItemPriority.Normal);
                item6.Caption = "显示/隐藏excel列头";
                e.Menu.Items.Add(item6);
            }
        }
        private void spreadsheetControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
        {
            if (e.MenuType == SpreadsheetMenuType.Cell)
            {
                // Remove the "Clear Contents" menu item.
                e.Menu.RemoveMenuItem(SpreadsheetCommandId.FormatClearContentsContextMenuItem);

                // Disable the "Hyperlink" menu item.
                e.Menu.DisableMenuItem(SpreadsheetCommandId.InsertHyperlinkContextMenuItem);

                // Create a menu item for the Spreadsheet command, which inserts a picture into a worksheet.
                ISpreadsheetCommandFactoryService service = (ISpreadsheetCommandFactoryService)spreadsheetControl1.GetService(typeof(ISpreadsheetCommandFactoryService));
                SpreadsheetCommand cmd = service.CreateCommand(SpreadsheetCommandId.InsertPicture);
                SpreadsheetMenuItemCommandWinAdapter menuItemCommandAdapter = new SpreadsheetMenuItemCommandWinAdapter(cmd);
                SpreadsheetMenuItem menuItem = (SpreadsheetMenuItem)menuItemCommandAdapter.CreateMenuItem(DevExpress.Utils.Menu.DXMenuItemPriority.Normal);
                menuItem.BeginGroup = true;
                e.Menu.Items.Add(menuItem);

                // Insert a new item into the Spreadsheet popup menu and handle its click event.
                SpreadsheetMenuItem myItem = new SpreadsheetMenuItem("My Menu Item", new EventHandler(MyClickHandler));
                e.Menu.Items.Add(myItem);
            }
        }