none
ToolStripControlHost Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found. Issue RRS feed

  • Question

  • Look at this example, which I cut and paste into my project as a test. (I will change this over to a checkbox, once I resolve this problem)

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx

     

    Now, here is the error I get in my designer.

     

    Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.
    Hide    

    at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    at System.ComponentModel.Design.DesignSurface.CreateInstance(Type type)
    at Microsoft.VisualStudio.Design.VSDesignSurface.CreateInstance(Type type)
    at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
    at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
    at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
    at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
    at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
    at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
     
     
    lovely right?
     
    Trying to track down the problem has provided only minimum leads.
     
    ARGH!
    Melegant

    Sunday, October 28, 2007 6:19 PM

Answers

  •  

    Hi Melegant,

    Based on my understanding, it is because that the ToolStripControlHost class doesn’t have a constructor with no parameter. To solve this problem, you can create your own ToolStripControlHost with a none-parameter constructor and make the ToolStripMonthCalendar inherited from your ToolStripControlHost. Try something like the following:

    Code Block

    namespace ToolStripControlHostP

    {

        //Declare a class that inherits from ToolStripControlHost.

        [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]

        public class ToolStripMonthCalendar : MyToolStripControlHost

        {

            // Call the base constructor passing in a MonthCalendar instance.

            public ToolStripMonthCalendar() : base(new MonthCalendar()) { }

     

            public MonthCalendar MonthCalendarControl

            {

                get

                {

                    return Control as MonthCalendar;

                }

            }

     

            // Expose the MonthCalendar.FirstDayOfWeek as a property.

            public Day FirstDayOfWeek

            {

                get

                {

                    return MonthCalendarControl.FirstDayOfWeek;

                }

                set { value = MonthCalendarControl.FirstDayOfWeek; }

            }

     

            // Expose the AddBoldedDate method.

            public void AddBoldedDate(DateTime dateToBold)

            {

                MonthCalendarControl.AddBoldedDate(dateToBold);

            }

     

            // Subscribe and unsubscribe the control events you wish to expose.

            protected override void OnSubscribeControlEvents(Control c)

            {

                // Call the base so the base events are connected.

                base.OnSubscribeControlEvents(c);

     

                // Cast the control to a MonthCalendar control.

                MonthCalendar monthCalendarControl = (MonthCalendar)c;

     

                // Add the event.

                monthCalendarControl.DateChanged +=

                    new DateRangeEventHandler(OnDateChanged);

            }

     

            protected override void OnUnsubscribeControlEvents(Control c)

            {

                // Call the base method so the basic events are unsubscribed.

                base.OnUnsubscribeControlEvents(c);

     

                // Cast the control to a MonthCalendar control.

                MonthCalendar monthCalendarControl = (MonthCalendar)c;

     

                // Remove the event.

                monthCalendarControl.DateChanged -=

                    new DateRangeEventHandler(OnDateChanged);

            }

     

            // Declare the DateChanged event.

            public event DateRangeEventHandler DateChanged;

     

            // Raise the DateChanged event.

            private void OnDateChanged(object sender, DateRangeEventArgs e)

            {

                if (DateChanged != null)

                {

                    DateChanged(this, e);

                }

            }

        }

     

        public class MyToolStripControlHost : ToolStripControlHost

        {

            public MyToolStripControlHost()

                : base(new Control())

            {

            }

            public MyToolStripControlHost(Control c)

                : base(c)

            {

            }

        }

    }

     

     

     

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Wednesday, October 31, 2007 11:45 AM