I'm developing a WinForms .NET application. I have few context menus which are used on various places including some user controls. There is no ultimate root form which could hold those menus (I could design in those form's designer) on a single place.
I would like to make those menus standalone controls and be able to drop them from Toolbox wherever I need. I know how to do it programmatically/dynamically but without designer support. Perhaps I'm just missing something.
- Is there a way how to make those menus design-able?
- What is the best practice?
You can create a reusable custom context menu which is available in toolbox. To do so, it's enough to create a public class in the project which inherits from
System.Windows.Forms.ContextMenuStrip
and put the codes for creating items in constructor of your class.Also you can do it using designer:
CustomContextMenuStrip
to your projectSystem.Windows.Forms.ContextMenuStrip
and save it.Items
property and add items that you need.InitializeComponent()
method. Go to code view of the file and add a public parameterless constructor and callInitializeComponent()
in it.Note:
Language
property which is available only in designer. This way your component itself is localizable, independent from host form.ContextMenuStrip
.ItemClicked
in forms.