Access VBA ControlType 属性
可以在 Visual Basic 中使用 ControlType 确定窗体或报表中的控件的类型。Byte 型,可读/写。
expression.ControlType
expression 必需。返回“应用于”列表中的一个对象的表达式。
设置
ControlType 属性是用于指定控件类型的固有常量。
常量 |
控件 |
acOptionButton |
|
注释 ControlType 属性只能通过使用 Visual Basic 在窗体设计视图或报表设计视图中设置,但能在所有视图中查看。
说明
ControlType 属性不仅可以用于在代码中检查特定控件的类型,也可以对控件类型进行更改。例如,可以在窗体“设计”视图中将文本框的 ControlType 属性更改为 acComboBox,使文本框变为组合框。
利用 ControlType 属性还可以根据特定的条件,改变窗体上相似控件的特征。例如,当不想让用户编辑文本框中已有的数据时,可以将所有文本框的 SpecialEffect 属性设置为“平面”,并将窗体的 AllowEdits 属性设置为“否”。(SpecialEffect 属性不影响是否可以编辑数据,它只提供一个控件行为已经更改的视觉提示。)
ControlType 还用于在使用 CreateControl 方法创建控件时指定控件类型。
示例
以下示例检查窗体上所有控件的 ControlType 属性。对所有标签和文本框控件,该过程切换其“SpecialEffect”属性。当标签的“特殊效果”属性设置为“凹陷”,且文本框的“特殊效果”属性设置为“普通”,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
文章转载:http://www.office-cn.net/t/acvba/html_acprocontroltype.htm
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现