WebBrowserControl 属性 (权限)WebBrowserControl.ControlType property (Access)

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

语法Syntax

表达式ControlTypeexpression.ControlType

_表达式_一个代表**WebBrowserControl** 对象的变量。expression A variable that represents a WebBrowserControl object.

说明Remarks

ControlType 属性设置为指定的控件类型的固有常量。The ControlType property setting is an intrinsic constant that specifies the control type. 有关由**CreateControl** 和**CreateReportControl** 方法创建的控件的完整列表, 请参阅**AcControlType** 枚举。For a complete list of controls created by the CreateControl and CreateReportControl methods, see the AcControlType enumeration.

[!注释] 只能通过使用 Visual Basic 窗体设计视图或报表设计视图中,设置 ControlType 属性,但它可以在所有视图中读取。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 属性很有用不仅检查代码中的特定控件类型但也更改为其他类型的控件的类型。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. 例如,可以通过在文本框中将 ControlType 属性设置为在窗体设计视图中的 acComboBox 到组合框中更改文本框。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 属性可以用于更改类似根据某些条件在窗体上的控件的特性。You can use the ControlType property to change characteristics of similar controls on a form according to certain conditions. 例如,如果您不希望用户能够编辑文本框中的现有数据,可以将所有文本框的 特殊效果 属性设置为平面并将窗体的 允许编辑 属性设置为 no。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 属性。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.

当 label 控件的SpecialEffect属性设置为 "阴影", 并且文本框控件的SpecialEffect属性设置为 "普通", 并且 "允许添加" ****、" **** 允许删除" 和 "允许编辑" 属性都设置为True, 则切换intCanEdit变量以允许对基础数据进行编辑。When the SpecialEffect property of the label control is set to Shadowed, and the SpecialEffect property of the text box control 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

支持和反馈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.