GridDesktops コンテキスト メニューの管理

序章

ContextMenuManager クラスは、コンテキスト メニュー項目を管理するために使用されます。 GridDesktop.ContextMenuManager 属性は、ContextMenuManager オブジェクトのインスタンスを取得します。たとえば、ContextMenuManager.MenuItemAvailable_Copy 属性は、コンテキスト メニュー項目 Copy が使用可能かどうかを示す値を取得または設定します。同様に、さまざまなコンテキスト メニュー項目に対応するすべての属性があります。

**重要:**デフォルトでは、すべてのコンテキスト メニュー項目がリストに表示されます。

コンテキスト メニューの管理

コンテキスト メニュー項目の非表示

このタスクを実行するには、まず GridDesktop にあるデフォルトのコンテキスト メニューを確認します。

GridDeskop のデフォルト メニュー

todo:画像_代替_文章

次に、以下のコードを使用していくつかのメニュー項目を非表示にします。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the ContextMenuManager
ContextMenuManager cmm = this.grdDataEntry.ContextMenuManager;
// Hide the Copy option in the context menu
cmm.MenuItemAvailable_Copy = false;
// Hide the InsertRow option in the context menu
cmm.MenuItemAvailable_InsertRow = false;
// Hide the Format Cell dialog box
cmm.MenuItemAvailable_FormatCells = false;

上記のコードを実行すると、一部のメニュー項目がユーザーに表示されなくなります。

一部のメニュー項目が非表示になっています

todo:画像_代替_文章

新しいメニュー項目の追加

次のコード スニペットを使用して、新しいコンテキスト メニュー項目をリストに追加します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the active worksheet
Worksheet sheet = grdDataEntry.GetActiveWorksheet();
// Set the total columns diaplyed in the grid
sheet.ColumnsCount = 15;
// Set the total rows displayed in the grid
sheet.RowsCount = 15;
// Define a new menu item and specify its event handler
MenuItem mi = new MenuItem("newMenuItem", new System.EventHandler(miClicked));
// Set the label
mi.Text = "New Item";
// Add the menu item to the GridDesktop's context menu
grdDataEntry.ContextMenu.MenuItems.Add(mi);

また、新しいコマンド/オプションのイベント ハンドラーも指定します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Event Handler for the new menu item
private void miClicked(object sender, EventArgs e)
{
MenuItem mi = (MenuItem)sender;
MessageBox.Show("miCliked: " + mi.Text);
}

上記のコードを実行すると、コンテキスト メニューに新しいメニュー項目が表示されます。セルをクリックするとメッセージも表示されます。

リストに新しいメニュー項目が追加されました

todo:画像_代替_文章