禁止在TextBox中输入的几种方法
时 间:2008-04-23 08:19:47
作 者:UMVsoft整理 ID:16 城市:江阴
摘 要:禁止在TextBox中输入的几种方法
正 文:
Text1.Locked = True
方法二:(无光标闪烁,不能输入、删除,界面变色、文字反白)
Text1.Enabled = False
方法三:(有光标闪烁,可删除,不能输入)
此法用两个API函数,略为复杂些。请在标准工程添加两个按钮和一个文本框:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const ES_NUMBER = &H2000&
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
Dim CurrentStyle As Long, NewStyle As Long
'返回正常样式
CurrentStyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
If Flag Then
CurrentStyle = CurrentStyle Or ES_NUMBER
Else
CurrentStyle = CurrentStyle And (Not ES_NUMBER)
End If
'设置新样式
NewStyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, CurrentStyle)
NumberText.Refresh '刷新
End Sub
Private Sub Command1_Click()
SetNumber Text1, True
Text1.SetFocus
End Sub
Private Sub Command2_Click()
SetNumber Text1, False
Text1.SetFocus
End Sub
Private Sub Form_Load()
Command1.Caption = "禁止输入"
Command2.Caption = "可以输入"
End Sub
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
学习心得
最新文章
- Inputbox输入密码打开查询的...(12.23)
- Access工资计算工具源码分享:...(12.20)
- Access快速开发平台--让li...(12.18)
- 【Access Dsum示例】用D...(12.16)
- Inputbox输入密码打开窗体的...(12.13)
- Access快速开发平台通用查询条...(12.10)
- Microsoft ActiveX...(12.09)
- 人事管理系统;基于Access快速...(12.07)
- Access资源管理器示例(12.06)
- Microsoft ActiveX...(12.04)