ComponentDesigner.OnSetComponentDefaults 方法



此 API 现已过时。

设置组件的默认属性。Sets the default properties for the component.

 virtual void OnSetComponentDefaults();
public virtual void OnSetComponentDefaults ();
[System.Obsolete("This method has been deprecated. Use InitializeNewComponent instead.")]
public virtual void OnSetComponentDefaults ();
abstract member OnSetComponentDefaults : unit -> unit
override this.OnSetComponentDefaults : unit -> unit
Public Overridable Sub OnSetComponentDefaults ()


初始化设计器时调用 OnSetComponentDefaultsOnSetComponentDefaults is called when the designer is initialized. 这使设计器可以为基本组件提供默认值。This allows the designer to provide default values for the base component.

此方法只调用一次:首次通过将组件从工具箱拖到设计图面来创建组件。This method is called only once: when you first create the component by dragging it from the Toolbox to the design surface. 以后对设计器的初始化不调用此方法。Subsequent initializations of the designer do not invoke this method.

此方法的默认实现将组件的默认属性设置为组件的名称(如果默认属性为字符串),并且该属性尚未设置。The default implementation of this method sets the default property of the component to the name of the component if the default property is a string and the property is not already set. 此方法可在派生类中实现,以自定义此设计器正在设计的组件的初始化。This method can be implemented in a derived class to customize the initialization of the component that this designer is designing.