Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
W tym artykule wyjaśniono, jak dodawać i usuwać elementy menu skrótów w formularzach systemu Windows.
Składnik Windows Forms ContextMenu zawiera menu często używanych poleceń, które są istotne dla wybranego obiektu. Elementy można dodać do menu skrótów, dodając obiekty MenuItem do kolekcji MenuItems.
Możesz trwale usunąć elementy z menu kontekstowego; jednak podczas działania programu bardziej odpowiednie może być ukrycie lub wyłączenie tych elementów.
Ważne
Mimo że MenuStrip i ContextMenuStrip zastępują i dodają funkcjonalność do kontrolek MainMenu i ContextMenu z poprzednich wersji, MainMenu i ContextMenu są zachowywane, aby zapewnić zgodność z poprzednimi wersjami oraz umożliwić przyszłe wykorzystanie, jeśli zdecydujesz.
Aby usunąć elementy z menu skrótów
Użyj metody Remove lub RemoveAt kolekcji MenuItems składnika ContextMenu, aby usunąć określony element menu.
' Removes the first item in the shortcut menu. ContextMenu1.MenuItems.RemoveAt(0) ' Removes a particular object from the shortcut menu. ContextMenu1.MenuItems.Remove(mnuItemNew)// Removes the first item in the shortcut menu. contextMenu1.MenuItems.RemoveAt(0); // Removes a particular object from the shortcut menu. contextMenu1.MenuItems.Remove(mnuItemNew);// Removes the first item in the shortcut menu. contextMenu1->MenuItems->RemoveAt(0); // Removes a particular object from the shortcut menu. contextMenu1->MenuItems->Remove(mnuItemNew);— lub —
Użyj metody
Clearz kolekcjiMenuItemsw składniku ContextMenu, aby usunąć wszystkie elementy z menu.ContextMenu1.MenuItems.Clear()contextMenu1.MenuItems.Clear();contextMenu1->MenuItems->Clear();
Zobacz także
.NET Desktop feedback