Form.DefaultControl 屬性 (Access)Form.DefaultControl property (Access)

DefaultControl屬性會傳回與您可以設定特定類型的特定表單上控制項的預設屬性的**控制項** 物件。The DefaultControl property returns a Control object with which you can set the default properties for a particular type of control on a particular form. 唯讀。Read-only.

語法Syntax

運算式DefaultControl(ControlType)expression.DefaultControl (ControlType)

expression 代表 Form 物件的變數。expression A variable that represents a Form object.

參數Parameters

名稱Name 必要/選用Required/Optional 資料類型Data type 描述Description
ControlTypeControlType 必要Required LongLong AcControlType 常數,指出準備要設定預設屬性設定值的控制項類型。An AcControlType constant that indicates the type of control for which default property settings are to be set.

註解Remarks

DefaultControl 屬性可讓您設定控制項的預設屬性從程式碼。The DefaultControl property enables you to set a control's default properties from code. 設定特定類型的控制項的預設屬性後,該類型的每個後續建立的控制項將會有相同的預設值。After you have set the default properties for a particular type of control, each subsequently created control of that type will have the same default values.

例如,如果您將預設命令按鈕的 FontSize 屬性設定為 12,每個新命令按鈕會有 12 點字型大小。For example, if you set the FontSize property of the default command button to 12, each new command button will have a font size of 12 points.

並非所有的控制項屬性都可以做為預設屬性。Not all of a control's properties are available as default properties. 有效之控制項的預設屬性是決定於控制項的類型。The default properties available for a control depend on the type of control.

DefaultControl屬性會傳回_ControlType_引數所指定類型的控制項物件。The DefaultControl property returns a Control object of the type specified by the ControlType argument. Control 物件代表的不實際表單上的控制項,但後來是所有範本的預設控制項而是建立該類型的控制項。This Control object doesn't represent an actual control on a form, but rather a default control that is a template for all subsequently created controls of that type. 設定預設的 DefaultControl 屬性來傳回以相同的方式會將設定個別的控制項在表單上的內容 控制項 物件的控制項屬性。You set the default control properties for the Control object returned by the DefaultControl property in the same manner that you would set properties for an individual control on a form.

只能在表單設計檢視或報表設計檢視中可用的 DefaultControl 屬性。The DefaultControl property can be used only in form Design view or report Design view. 如果您嘗試將這個屬性套用至表單或報表不在設計檢視中,會產生執行階段錯誤。If you try to apply this property to a form or report that is not in Design view, a run-time error will result.

如果您嘗試將無法設定為使用 DefaultControl 屬性的預設屬性的屬性設定,則會產生執行階段錯誤。If you try to set a property that can't be set as a default property with the DefaultControl property, a run-time error will result. 若要決定哪些屬性可以是預設的屬性,列出的 DefaultControl 屬性所傳回的 控制項 物件的 Properties 集合。To determine which properties can be default properties, list the Properties collection of the Control object returned by the DefaultControl property.

範例Example

下列範例會建立新表單,並使用DefaultControl屬性來傳回代表預設命令按鈕控制項物件。The following example creates a new form and uses the DefaultControl property to return a Control object that represents the default command button. 程序設定某些命令按鈕的預設屬性,然後在表單上建立新的命令按鈕。The procedure sets some of the default properties for the command button, and then creates a new command button on the form.

Sub SetDefaultProperties() 
 Dim frm As Form, ctlDefault As Control, ctlNew As Control 
 
 ' Create new form. 
 Set frm = CreateForm 
 ' Return Control object representing default command button. 
 Set ctlDefault = frm.DefaultControl(acCommandButton) 
 ' Set some default properties. 
 With ctlDefault 
 .FontWeight = 700 
 .FontSize = 12 
 .Width = 3000 
 .Height = 1000 
 End With 
 ' Create new command button. 
 Set ctlNew = CreateControl(frm.Name, acCommandButton, , , , 500, 500) 
 ' Set control's caption. 
 ctlNew.caption = "New Command Button" 
 ' Restore form. 
 DoCmd.Restore 
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.