首先,在窗体中建立一个“线”控件,并把它的索引号定为0。接着,添加如下的代码:
Private Sub SetErrorState(ByVal ErrorState As Boolean, _
ByRef Control As Control)
On Error Resume Next
Load linError(Control.Index)
With linError(Control.Index)
Set .Container = Control.Container
.X1 = Control.Left
.X2 = Control.Left Control.Width
.Y1 = Control.Top Control.Height 10
.Y2 = Control.Top Control.Height 10
.BorderColor = VBRed
.Visible = ErrorState
End With
End Sub
以上程序将会在一个控件数组中建立新的线以匹配引入的控件。然后,设置线的容器以处理标签控件中的文本框。它设置了线的位置和颜色,如果ErrorState为True,线为可见。
在文本框的Validate事件添加以下代码,以调用SetErrorState方法:
If Text1(Index).Text = "1" Then
注释:==Valid
Call SetErrorState(False, Text1(Index))
Else
注释:==Invalid
Call SetErrorState(True, Text1(Index))
End If
相比于信息对话框,使用行来显示错误状态很少打断开发人员的编程思路,并且这一方法很容易学会。
上一篇: 使用文件的默认的打开方式
下一篇: 获得Windows的临时文件的路径
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



