Table of contents
TOC
折叠目录
展开目录

EmptyCell.ControlType 属性 (访问)EmptyCell.ControlType Property (Access)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

在 Visual Basic 中,可以使用ControlType属性来确定窗体或报表上的控件的类型。读取/写入字节You can use the ControlType property in Visual Basic to determine the type of a control on a form or report. Read/write Byte.

语法Syntax

表达式ControlTypeexpression. ControlType

表达式_一个表示EmptyCell对象的变量。_expression A variable that represents an EmptyCell object.

注解Remarks

ControlType属性设置为指定的控件类型的固有常量。The ControlType property setting is an intrinsic constant that specifies the control type.

常量Constant控件Control
acBoundObjectFrameacBoundObjectFrame绑定的对象框Bound object frame
acCheckBoxacCheckBox复选框Check box
acComboBoxacComboBox组合框Combo box
acCommandButtonacCommandButton命令按钮Command button
acCustomControlacCustomControl(自定义) 的 ActiveX 控件ActiveX (custom) control
acImageacImage图像Image
acLabelacLabel标签Label
acLineacLineLineLine
acListBoxacListBox列表框List box
acObjectFrameacObjectFrame未绑定对象框图表Unbound object frameor Chart
acOptionButtonacOptionButton选项按钮Option button
acOptionGroupacOptionGroup选项组Option group
acPageacPagePagePage
acPageBreakacPageBreak分页符Page break
acRectangleacRectangle矩形Rectangle
acSubformacSubform子窗体/子报表Subform/subreport
acTabCtlacTabCtlTabTab
acTextBoxacTextBox文本框中Text box
acToggleButtonacToggleButton切换按钮切换按钮Toggle buttonToggle button

请注意 只能通过使用 Visual Basic 窗体设计视图或报表设计视图中,设置ControlType属性,但它可以在所有视图中读取。Note The ControlType property can only be set by using Visual Basic in form Design view or report Design view, but it can be read in all views.

ControlType属性很有用不仅检查代码中的特定控件类型但也更改为其他类型的控件的类型。例如,可以通过在文本框中将ControlType属性设置为在窗体设计视图中的acComboBox到组合框中更改文本框。The ControlType property is useful not only for checking for a specific control type in code, but also for changing the type of control to another type. For example, you can change a text box to a combo box by setting the ControlType property for the text box to acComboBox while in form Design view.

ControlType属性可以用于更改类似根据某些条件在窗体上的控件的特性。例如,如果您不希望用户能够编辑文本框中的现有数据,可以将所有文本框的特殊效果属性设置为平面并将窗体的允许编辑属性设置为 no。 (特殊效果属性不会影响是否可以编辑数据则它用于此处提供的控件行为已更改的可视提示。)You can use the ControlType property to change characteristics of similar controls on a form according to certain conditions. For example, if you don't want users to edit existing data in text boxes, you can set the SpecialEffect property for all text boxes to Flat and set the form's AllowEdits property to No. (The SpecialEffect property doesn't affect whether data can be edited; it's used here to provide a visual cue that the control behavior has changed.)

ControlType属性还用于指定要使用CreateControl方法时创建的控件的类型。The ControlType property is also used to specify the type of control to create when you are using the CreateControl method.

示例Example

下面的示例检查在窗体上所有控件的ControlType属性。对于每个标签和文本框控件,该过程切换为这些控件的特殊效果属性。当标签控件的特殊效果属性设置为阴影和文本框控件的特殊效果属性设置为普通和允许添加时,允许删除,并更改属性是所有设置为True,则intCanEdit变量切换允许编辑的基础数据。The following example examines the ControlType property for all controls on a form. For each label and text box control, the procedure toggles the SpecialEffect property for those controls. When the label controls' SpecialEffect property is set to Shadowed and the text box controls' SpecialEffect property is set to Normal and the AllowAdditions, AllowDeletions, and AllowEdits properties are all set to True, the intCanEdit variable is toggled to allow editing of the underlying data.

Sub ToggleControl(frm As Form) 
 Dim ctl As Control 
 Dim intI As Integer, intCanEdit As Integer 
 Const conTransparent = 0 
 Const conWhite = 16777215 
 For Each ctl in frm.Controls 
 With ctl 
 Select Case .ControlType 
 Case acLabel 
 If .SpecialEffect = acEffectShadow Then 
 .SpecialEffect = acEffectNormal 
 .BorderStyle = conTransparent 
 intCanEdit = True 
 Else 
 .SpecialEffect = acEffectShadow 
 intCanEdit = False 
 End If 
 Case acTextBox 
 If .SpecialEffect = acEffectNormal Then 
 .SpecialEffect = acEffectSunken 
 .BackColor = conWhite 
 Else 
 .SpecialEffect = acEffectNormal 
 .BackColor = frm.Detail.BackColor 
 End If 
 End Select 
 End With 
 Next ctl 
 If intCanEdit = IFalse Then 
 With frm 
 .AllowAdditions = False 
 .AllowDeletions = False 
 .AllowEdits = False 
 End With 
 Else 
 With frm 
 .AllowAdditions = True 
 .AllowDeletions = True 
 .AllowEdits = True 
 End With 
 End If 
End Sub

另请参阅See also

概念Concepts

EmptyCell 对象EmptyCell Object

© 2018 Microsoft