当我拖放用户控件并更改属性ComponentType时,他找不到方法ComponentLogicFactory.CreateInstance(_ComponentType)。当我重建或编译时,编译器没有显示任何错误,当我运行模拟时,一切正常。我看着遮阳篷 WinForm designer error open designer,但对我来说没有,我有一个默认的构造函数。我没有使用单例或在运行时设置的任何变量。可能是什么原因?
public ComponentTypes ComponentType
{
get
{
return this._ComponentType;
}
set
{
if(component == null)
{
_ComponentType = value;
component = ComponentDesignFactory.CreateInstance(_ComponentType);
if (!DesignMode)
{
logicChip = ComponentLogicFactory.CreateInstance(_ComponentType);
}
if(NumberInputPins > component.MaxInput)
{
this.NumberInputPins = component.MaxInput;
}
if(NumberOutputPins > component.MaxOutput)
{
this.NumberOutputPins = component.MaxOutput;
}
RepositionComponent();
gridPanel.Controls.Add(component);
}
else
{
MessageBox.Show("You can only change this once");
}
}
}
private static readonly IDictionary<ComponentTypes, Func<IComponent>> Creator =
new Dictionary<ComponentTypes, Func<IComponent>>()
{
{ ComponentTypes.And, () => new AndLogic() },
{ ComponentTypes.Or, () => new OrLogic() },
{ ComponentTypes.Not, () => new NotLogic() },
{ ComponentTypes.Led, () => new LedLogic() },
{ ComponentTypes.On, () => new OnLogic() },
{ ComponentTypes.Off, () => new OffLogic() },
{ ComponentTypes.Clock, () => new ClockLogic() },
};
public static IComponent CreateInstance(ComponentTypes typeComponent)
{
return Creator[typeComponent]();
}