Windows Forms에서 바로 가기 메뉴 항목을 추가하고 제거하는 방법을 설명합니다.
Windows Forms ContextMenu 구성 요소는 선택한 개체와 관련된 자주 사용되는 명령 메뉴를 제공합니다. MenuItem 개체를 MenuItems 컬렉션에 추가하여 바로 가기 메뉴에 항목을 추가할 수 있습니다.
바로 가기 메뉴에서 항목을 영구적으로 제거할 수 있습니다. 그러나 런타임에 항목을 숨기거나 사용하지 않도록 설정하는 것이 더 적합할 수 있습니다.
중요합니다
MenuStrip
과 ContextMenuStrip
은 MainMenu 및 ContextMenu 컨트롤에 새로운 기능이 추가된 것으로, 이전 컨트롤 버전을 대체합니다. 그러나 이전 버전과의 호환성 및 앞으로의 사용 가능성을 고려하여 MainMenu와 ContextMenu를 유지하도록 선택할 수 있습니다.
바로 가기 메뉴에서 항목을 제거하려면
ContextMenu 구성 요소 MenuItems 컬렉션의 Remove 또는 RemoveAt 메서드를 사용하여 특정 메뉴 항목을 제거합니다.
' 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);
-또는-
ContextMenu 구성 요소
MenuItems
컬렉션의Clear
메서드를 사용하여 메뉴에서 모든 항목을 제거합니다.ContextMenu1.MenuItems.Clear()
contextMenu1.MenuItems.Clear();
contextMenu1->MenuItems->Clear();
참고하십시오
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback