can't access to properties and events of my custom control inherited from ToolStripControlHost in designer

679 Views Asked by At

I'm looking to make a custom ContextMenu item which is composed of simply a FlowLayoutPanel containing a Label and a ComboBox. I want to be able to access the properties and events of my custom control at design-time in the designer of visual studio 2013. I want to be able to use my custom control in a MenuStrip, in a ToolStripMenuItem or in a ContextMenu. My actual problem is that everything is working fine if I insert the control directly in a MenuStrip but I can't access the property window of my control when it is in a ToolStripMenuItem or in a ContextMenu. The property window is all white and the control is glitchy in the designer.

So Here is my code(I didn't implement any properties nor any events yet but I should have access to inherited properties and events in property window anyway. In fact, I do when I insert the control in a MenuStrip but not in the other two.)

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace CustomControlLib
{
    [ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.MenuStrip        | ToolStripItemDesignerAvailability.ToolStrip |    ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class LblCboxStripControl : ToolStripControlHost
    {
        private Label controlName;
        private ComboBox controlComboBox;
        private FlowLayoutPanel controlPanel;

        public LblCboxStripControl()
            : base(CreateControlInstance())
        {
            controlPanel = (FlowLayoutPanel)base.Control;
            controlPanel.AutoSize = true;
            controlPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            controlPanel.BackColor = Color.Transparent;

            controlName = new Label();
            controlName.BackColor = Color.Transparent;
            controlName.AutoSize = true;
            controlName.Dock = DockStyle.None;
            controlName.Text = "Control name";

            controlComboBox = new ComboBox();

            controlPanel.Controls.Add(controlName);
            controlPanel.Controls.Add(controlComboBox);
        }

        public static FlowLayoutPanel CreateControlInstance()
        {
            FlowLayoutPanel flp = new FlowLayoutPanel();
            return flp;
        }
    }
}

I've seen a similar post here: .NET Custom Control (ToolStripControlHost) Wreaks Havoc on the Designer

but the only solution there is to create a class which inherits form ToolStripControlHost and provides a constructor without arguments doesn't solve my problem at all. I also tried creating new empty projects, restarting VS and putting the class inside the form project or in an extern library doesn't solve it either. I'd also add that there is nothing unusual in the Form.designer file.

0

There are 0 best solutions below