Visual Studio isn't initializing your MyContextMenuStrip
with a Container
because your control doesn't have a constructor that accepts a Container
as a parameter.
Create a constructor in your MyContextMenuStrip
that takes a System.ComponentModel.IContainer
and then pass this parameter to your control's base class using the base
keyword:
class MyContextMenuStrip : ContextMenuStrip
{
public MyContextMenuStrip(System.ComponentModel.IContainer c) : base(c) { }
}
After doing this you'll find that when you add your MyContextMenuStrip
to a Form using the designer, VS will generate the code you want in your Form's InitializeComponent
method:
this.myContextMenuStrip1 = new WindowsFormsApplication1.MyContextMenuStrip(this.components);