TextBox.ControlType 属性 (Access)

您所在的位置:网站首页 access中标签控件 TextBox.ControlType 属性 (Access)

TextBox.ControlType 属性 (Access)

2024-07-17 02:38| 来源: 网络整理| 查看: 265

TextBox.ControlType 属性 (Access) 项目04/07/2023

使用 Visual Basic 中的 ControlType 属性确定窗体或报表上的控件类型。 可读/写 Byte 类型。

语法

表达式。ControlType

表达 一个代表 TextBox 对象的变量。

备注

ControlType 属性设置为指定的控件类型的固有常量。 有关 CreateControl 和 CreateReportControl 方法创建的控件的完整列表,请参阅 AcControlType 枚举。

[!注释] 只能通过使用 Visual Basic 窗体设计视图或报表设计视图中,设置 ControlType 属性,但它可以在所有视图中读取。

ControlType 属性很有用不仅检查代码中的特定控件类型但也更改为其他类型的控件的类型。 例如,可以通过在文本框中将 ControlType 属性设置为在窗体设计视图中的 acComboBox 到组合框中更改文本框。

使用 ControlType 属性可以根据特定条件更改窗体上类似控件的特征。 例如,如果您不希望用户能够编辑文本框中的现有数据,可以将所有文本框的 特殊效果 属性设置为平面并将窗体的 允许编辑 属性设置为 no。 (是否可以编辑数据,并不会影响 特殊效果 属性; 它用于此处提供的视觉提示的控件行为已更改)。

ControlType 属性还用于指定要在使用 CreateControl 方法时创建的控件的类型。

示例

下面的示例检查在窗体上所有控件的 ControlType 属性。 对于每个标签和文本框控件,该过程切换为这些控件的 特殊效果 属性。

当标签控件的 SpecialEffect 属性设置为 Shadowed,文本框控件的 SpecialEffect 属性设置为 Normal,并且 AllowAdditions、 AllowDeletions 和 AllowEdits 属性都设置为 True 时, intCanEdit 该变量将切换为允许编辑基础数据。

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

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3