3

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.

Community
  • 1
  • 1
m0n0nk
  • 31
  • 2
  • Were you able to solve this? – Rev May 28 '14 at 07:50
  • No, I still don't know why I have this bug. – m0n0nk May 29 '14 at 12:05
  • Hmm ok. I have exactly the same problem with VS2008. I followed [this tutorial](http://msdn.microsoft.com/en-us/library/9k5etstz(v=vs.90).aspx) to wrap a NumericUpDown. Everything is working fine except the property view in the designer. Well, since its no big deal to initialize the control manually, its not so critical but a fix would've been nice. – Rev May 30 '14 at 11:12

0 Answers0