I'm having some problems in VS2019 with UserControls.
I have a base user control (WinForms) that I want all my other User Controls to be inherited from. THe base control provides a number of common properties that I need.
public partial class MyBaseControl : System.Windows.Forms.UserControl
{
internal Int32 _caseID;
internal object _objectID;
public int CaseID { get => _caseID; set => _caseID = value; }
public object ObjectID { get => _objectID; set => _objectID = value; }
internal virtual void MakeScreenReadOnly()
{
}
public MyBaseControl()
{
Type systemType = this.GetType();
PropertyInfo propertyInfo = systemType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
this.AutoScroll = true;
}
}
The controls that inherit this base control all work fine when the application runs, except I can't view the control in the designer. The user control is
public partial class AddressControl : MyBaseControl
{
....
}
I get the error
The service System.Windows.Forms.Design.IEventHandlerService already exists in the service container. Parameter name: serviceType
when trying to view AddressControl in the designer.
This used to work, in earlier version of Visual Studio. Does anyone have any ideas ?
this.DoubleBuffered = true;orthis.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);in its constructor. -- See that you don't have duplicated attributes, e.g.,[Designer(GetType(...)]in both base and derived classes. In this case, remove the attribute form the derived class. -- Don't do anything Design-time/Design-Mode related in the base class (checkif (DesignMode) (...)), especially in theLoadevent. If something needs to be set, overrideOnHandleCreated()orOnLayout()or both. - Jimi